Action to control Spotify only

Hello everyone..

I have small question

I want to make Trackpad Gesture or Keyboard Shortcut to Play/Pause for Spotify,
I know there is Predefined Action for Play/Pause but it is act like the normal Media Keys, and that not what I want..

so what is the best way to do that?

Thanks..

You can do this with an applescript action!

The code is easy, something like:

tell application "Spotify" to playpause

The code I use is a bit more complicated. It won't open spotify randomly and it also stabilises the action so that if an error happens it'll be fine.

--control Spotify playback directly and not something else

if application "Spotify" is running then
	tell application "Spotify"
		try
			playpause
		on error
			return "-"
		end try
	end tell
else
	return "-"
end if

This code is from my preset AquaTouch, which has app-specific play/pause buttons for iTunes, Spotify and YouTube. Check it out!

2 Likes

Thank you very very much..

I used the second one and it's just works as I want,
this actually the first time I tried to use AppleScript action, and I'm impressed how powerful and simple to use it,

Is there any post here for people who want to learn the syntax and how to make a good scripts?

I don't have MBP with TouchBar but I will take a look on your preset, and I'm sure I will find many of useful ideas to try..

Thanks again!

When I started with AquaTouch I didn't have any experience with AppleScript either.

What I did to learn was I explored other people's presets and tried to modify them to my needs.
I have some experience with coding but after lots of experimentation I have the skills I have now. Since the syntax is pretty easy and applescript has the ability to autocorrect it's syntax, it was pretty easy to learn

I suggest exploring my preset (since I guess it has the most scripts) with a TouchBar Simulator:

Then, after reading a bunch of code, open the "AppleScript Editor" on your Mac to bring up well, the editor, and tweak around.

There is a hammer and a play button there, the hammer button is a 'check code' which is very useful to debug without running the script. To run the script press the play button.

One thing to note: To automate an app with applescript it must support applescript!
On the AppleScript Editor, choose: File; Open Dictionary... and pick an app to see it's specific commands. If it's not in the list then it's not supported with applescript.

More information is also online about other general tools, I suggest apple's own documents and stackoverflow answers
https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html#//apple_ref/doc/uid/TP40000983-CH208-SW1

If you need any more help or would like to know how to do what you want, no need to hesitate to ask here in the community!

2 Likes

Thank you very much I really appreciate your time :rose:

The work you are doing is really impressive..

and thanks for these tips and important information..

I wish you a wonderful day..

1 Like