snipt

Ctrl+h for KB shortcuts

AppleScript

Next Track in Rdio/iTunes

on is_running(appName)
	tell application "System Events" to (name of processes) contains appName
end is_running

set rdRunning to is_running("Rdio")

if rdRunning then
	run script "tell application \"Rdio\" 
	next track
	end tell"
else 
	run script "tell application \"iTunes\" 
	play next track
	end tell"
end if

Description

I'm using this script to map F12 in an Alfred.app workflow to trigger next track in Rdio if open, otherwise iTunes. Alfred requires a script action with /usr/bin/osascript as the language
https://snipt.net/embed/cff8a226c538eb702922f49e449f152c/
/raw/cff8a226c538eb702922f49e449f152c/
cff8a226c538eb702922f49e449f152c
applescript
AppleScript
15
2019-06-20T05:32:34
True
False
False
Aug 21, 2013 at 08:41 PM
/api/public/snipt/76089/
next-track-in-rdioitunes
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a> <a href="#L-13">13</a> <a href="#L-14">14</a> <a href="#L-15">15</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">on</span> <span class="nv">is_running</span><span class="p">(</span><span class="nv">appName</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">tell</span> <span class="nb">application</span> <span class="s2">&quot;System Events&quot;</span> <span class="k">to</span> <span class="p">(</span><span class="na">name</span> <span class="k">of</span> <span class="nv">processes</span><span class="p">)</span> <span class="ow">contains</span> <span class="nv">appName</span> </span><span id="L-3"><a name="L-3"></a><span class="k">end</span> <span class="nv">is_running</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="k">set</span> <span class="nv">rdRunning</span> <span class="k">to</span> <span class="nv">is_running</span><span class="p">(</span><span class="s2">&quot;Rdio&quot;</span><span class="p">)</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a><span class="k">if</span> <span class="nv">rdRunning</span> <span class="k">then</span> </span><span id="L-8"><a name="L-8"></a> <span class="nb">run script</span> <span class="s2">&quot;tell application \&quot;Rdio\&quot; </span> </span><span id="L-9"><a name="L-9"></a><span class="s2"> next track</span> </span><span id="L-10"><a name="L-10"></a><span class="s2"> end tell&quot;</span> </span><span id="L-11"><a name="L-11"></a><span class="k">else</span> </span><span id="L-12"><a name="L-12"></a> <span class="nb">run script</span> <span class="s2">&quot;tell application \&quot;iTunes\&quot; </span> </span><span id="L-13"><a name="L-13"></a><span class="s2"> play next track</span> </span><span id="L-14"><a name="L-14"></a><span class="s2"> end tell&quot;</span> </span><span id="L-15"><a name="L-15"></a><span class="k">end</span> <span class="k">if</span> </span></pre></div> </td></tr></table>
alfred, mac, rdio