Fork me on GitHub

Spotify Applescripts Version 0.4.3

NEW! Updated version of the Applescripts available here

With the new version of Spotify the menus have been moved around, so I have updated the Applescripts that you can use to control Spotify with Quicksilver.
Play Next

 
tell application "System Events"
	set MyList to (name of every process)
end tell
 
tell application "System Events" to set appList to ¬
	name of application processes whose frontmost is true
 
set activeApp to item 1 of appList
if (MyList contains "Spotify") is true then
	tell application "Spotify" to activate
	tell application "System Events"
		tell process "Spotify"
click menu item 3 of menu 1 of menu bar item 6 of menu bar 1
		end tell
	end tell
	tell application "System Events"
		set visible of process "Spotify" to false
	end tell
end if
 

Play Previous

 
tell application "System Events"
	set MyList to (name of every process)
end tell
 
tell application "System Events" to set appList to ¬
	name of application processes whose frontmost is true
 
set activeApp to item 1 of appList
if (MyList contains "Spotify") is true then
	tell application "Spotify" to activate
	tell application "System Events"
		tell process "Spotify"
click menu item 4 of menu 1 of menu bar item 6 of menu bar 1
		end tell
	end tell
	tell application "System Events"
		set visible of process "Spotify" to false
	end tell
end if
 

Play/Pause

 
tell application "System Events"
	set MyList to (name of every process)
end tell
 
tell application "System Events" to set appList to ¬
	name of application processes whose frontmost is true
 
set activeApp to item 1 of appList
if (MyList contains "Spotify") is true then
	tell application "Spotify" to activate
	tell application "System Events"
		tell process "Spotify"
click menu item 1 of menu 1 of menu bar item 6 of menu bar 1
		end tell
	end tell
	tell application "System Events"
		set visible of process "Spotify" to false
	end tell
end if
 

Related posts:

  1. Spotify Applescripts – Updated
  2. Controlling Spotify through Applescript & Quicksilver.
  3. Toy Story 3 Trailer
  4. What exactly is AI?
  5. The Problem with Making Apps for a closed market.
28
Apr 2010
POSTED BY
POSTED IN Blog
DISCUSSION 16 Comments
TAGS

16 Responses to : Spotify Applescripts Version 0.4.3

  1. Nik says:

    Interesting.. I was using the original scripts you posted and when they stopped working simply adjust the menu counts. What does the additional set MyList etc do?

  2. Jack says:

    MyList is basically the list of currently running programs, so if you have spotify hidden or not the current active program. The apple script will go and make Spotify the foremost application so that the menu modifiers work.

  3. It does bring my Spotify to the front, but doesn’t affect play/pause state. I’m using Spotify (Premium) player version 4.3.427

  4. I got it to work by commenting out the mouse click simulation and putting ‘keystroke ” “‘ instead :-)

  5. JimR says:

    Add Search?

    tell application “Spotify” to activate
    tell application “System Events”
    tell process “Spotify”
    click menu item 17 of menu 1 of menu bar item 4 of menu bar 1
    keystroke “pet shop boys, it’s a sin”
    key code 36
    delay 1
    key code 48
    key code 48
    key code 36
    end tell
    end tell

  6. Ruaridh says:

    I’ve written a little app that lets you assign hotkeys to spotify actions, feel free to check it out and let me know what you think. :)

  7. Ruaridh says:

    Woops, realised I haven’t linked it:

    http://lifeupnorth.co.uk/lun/#5

  8. Great script. Really useful. What would be even better is if it could also support Spaces. Currently if I run the script it will change the current space to whichever space spotify is running in. It would be great to have it either stay in the space I am in or at least return to the space I was in.

  9. Jack says:

    I have only just realised how irratating the scripts are when using spaces. I am working on an update that should stop the spaces jumping problem.

  10. Mats A. says:

    Anyone having any idea on whats wrong when im just getting the Spotify window to appear,, theres no change in the program itself.

  11. Simon says:

    Just want to say thanks for this and that it works perfect! Was looking for a mini player to skip track without having to open Spotify, however, this solution is far better as I can now skip a song using an unused mouse button that I had. Perfect.

    @disretrospect, it does switch spaces, yes, but cross Spotify so it is closed. Now it doesn’t switch spaces when the script is ran.

  12. Timo says:

    @Simon Nice idea of closing the Spotify window, but that does not really solve the problem. The active app still changes to Spotify (although window stays the same), but it should switch back to the program that was used when the script was activated.

    Anyone getting the Spaces to work?

    Still this is great!

  13. orta says:

    people with spaces problems, have you tried setting spotify to be on “All Spaces” in the options? that in theory should make it not switch

  14. Aaron Lidman says:

    Hello any/everyone, these scripts helped me out in the past and I’ve since learned Spotify has official Applescript support which makes things much easier. Hacks that bring the application in focus are no longer needed and everything can be seamlessly done just with the script running in the background.

    Here are my modified scripts: (if Spotify is not running it will not launch it)
    - Next track

    tell application “System Events”
    set MyList to (name of every process)
    end tell
    if (MyList contains “Spotify”) is true then
    tell application “Spotify” to next track
    end if

    -Pause/Play

    tell application “System Events”
    set MyList to (name of every process)
    end tell
    if (MyList contains “Spotify”) is true then
    tell application “Spotify” to playpause
    end if

    -Previous track

    tell application “System Events”
    set MyList to (name of every process)
    end tell
    if (MyList contains “Spotify”) is true then
    tell application “Spotify” to previous track
    end if

  15. Pingback: Spotify Applescripts – 0.5.2

  16. Jack says:

    Aaron nice spot, completely passed me by. I have posted new updates, do you have a website so I can link??

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>