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..
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!
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..
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.