{"id":949,"date":"2022-09-20T08:49:58","date_gmt":"2022-09-20T12:49:58","guid":{"rendered":"http:\/\/tech.creed3.com\/?p=949"},"modified":"2022-09-16T09:16:56","modified_gmt":"2022-09-16T13:16:56","slug":"reascript-lua-get-the-track-name","status":"publish","type":"post","link":"https:\/\/tech.creed3.com\/?p=949","title":{"rendered":"Reascript \/ Lua : Get The Track name"},"content":{"rendered":"<p>I&#8217;m pretty experienced in scripting, mainly web related, but a few different languages. &nbsp;I&#8217;ve dabbled in AppleScript as well. &nbsp;Thought about C (or the various flavors of it) but never committed to learning. After some time I have decided to try my hand at scripting for Reaper, the DAW.<!--more--><\/p>\n<p>In my first attempt I wanted to get the name of a selected track in a project and simply display that in a message to verify I was getting it correctly. &nbsp;But I kept getting errors. &nbsp;Errors I wasn&#8217;t immediately about to figure out. &nbsp;It seems silly now that I have it, but this is the sort of thing you can expect when learning a new language. &nbsp;And sadly the <a href=\"https:\/\/www.reaper.fm\/sdk\/reascript\/reascripthelp.html\" rel=\"noopener\" target=\"_blank\">Reaper API Documentation<\/a> doesn&#8217;t come with examples or much help in sorting it all out. &nbsp;I spent quite a while searching online and the <a href=\"https:\/\/forum.cockos.com\/\" rel=\"noopener\" target=\"_blank\">Reaper forums<\/a> trying to find an answer for why my script wasn&#8217;t working.<\/p>\n<p>So hopefully this snippet could save you some time. Select a track and run the script. &nbsp;If no track is selected you&#8217;ll be asked to select one. &nbsp;Otherwise you&#8217;ll see a message displaying the name of the track you selected followed by the name of the track in the console window.<\/p>\n<pre><code style=\"font-size:12px;\">sel_track = reaper.GetSelectedTrack(0,0)\r\n\r\nif sel_track then\r\n  &nbsp; -- do things to the track\r\n  &nbsp; _, sel_track_name = reaper.GetTrackName(sel_track, \"\")\r\n  &nbsp; reaper.ShowMessageBox(sel_track_name,\"Selected Track:\",0)\r\n  &nbsp; reaper.ShowConsoleMsg(sel_track_name)\r\nelse\r\n  &nbsp; reaper.ShowMessageBox(\"Please select a track!\", \"Error\", 0)\r\nend<\/code><\/pre>\n<p>There&#8217;s also a searchable Reaper API posted by Raymond Radet (X-Raym) <a href=\"https:\/\/www.extremraym.com\/cloud\/reascript-doc\/\" rel=\"noopener\" target=\"_blank\">HERE<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m pretty experienced in scripting, mainly web related, but a few different languages. &nbsp;I&#8217;ve dabbled in AppleScript as well. &nbsp;Thought about C (or the various flavors of it) but never committed to learning. After some time I have decided to try my hand at scripting for Reaper, the DAW.<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[88,87,89],"tags":[],"class_list":["post-949","post","type-post","status-publish","format-standard","hentry","category-reaper","category-recording","category-scripting-in-reaper"],"views":1182,"_links":{"self":[{"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/posts\/949","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=949"}],"version-history":[{"count":0,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/posts\/949\/revisions"}],"wp:attachment":[{"href":"https:\/\/tech.creed3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}