-- Invoke Spotify simply by opening a Spotify playlist or artist URL
open location "http://open.spotify.com/artist/4Zml6rzsSiVkfIIWJh6EWX"
-- Make sure we have the spotify-application on front and in focus
tell application "Spotify"
activate
end tell
-- Now navigate to the song we want to play and play it
tell application "System Events"
-- Three times tabulator = move selection to the songs list
key code 48
key code 48
key code 48
-- Wait for a while the spotify app to catch up
delay (2)
-- enter key = play selected song
key code 36
-- right key with command = next song (random assumed)
key code 124 using command down
end tell
Other assumptions:
- "enable access to assistive devices" is enabled on the "Universal Access" -settings
- Spotify URL:s properly associated to your favourite browser (tested only with firefox)
- Invoking a random song requires you to set the shuffle on manually on the Spotify app
- Naturally this generates new browser tabs on each time the script is invoked
- As the key events are used, and even with a noticeable wait in between, this can cause really weird results if something is happening onscreen either interactively or autonomously.
- There is no straightforward way of knowing if Spotify is already playing something. Toggling the playback off, if invoked second time (useful when used with RFID tags) isn't therefore easy.. or is there a apparent solution other than closing the app?
Again, the script is not really a rocket science and most of the elements were just copy&pasted from invaluable Doug's AppleScripts. It is just fun to simply being able to control other apps in OSX!
5 comments:
Brilliant!
I just googled for this and it's just what I needed. Thank you.
My use case, if you're interested, is that I have a 25 minute ambient playlist that I want to trigger every time I start a new Pomodoro.
Pomodoro.app allows you to script events for beginning, pausing and ending... so this works great.
Thanks for posting!
Thanks for help. I used the script to lauch Spotify with my Powermate.
I didn't notice that you're from Finland before seeing that Titi-Nalle thing. Funny.
I don't know whether Spotify has changed it's behavior but I didn't need the tabs nor the return. I only added a command to press space (key code 49).
spotifypremiumapk.live free download the premium version
Thanks for the script, works fine for Spotify Plays!
Buy Purchase and Recharge Now: Amantel - International Calling APK
With Amantel Login & Signup, there are two ways for you to call internationally:
International calls to anyone, anywhere
With our subscriptions, you can connect as much as you want to
any cell phone or landline and Mobile phone in more than 70 countries.
Or you can choose the World Credits prepaid payment method and Online Recharge payment to call any country in the world with the lowest possible rates.
Call Trinidad Tobago
Call Ukraine
Post a Comment