Saturday, January 16, 2021

#1 2020-11-30 04:58:12 am

KevS
Member
Registered: 2017-05-23
Posts: 14

Basic keystroke script works in Script Editor, but not when launched

I made a script to launch and then play/pause Spotify:

Applescript:

tell application "System Events"
   tell application "Spotify" to activate
   delay 0.2
   key code 49 --spacebar
   delay 0.2
   set visible of process "Spotify" to false
   delay 0.2
end tell

When I run the script in Script Editor, it works fine. However, when I launch it (I use BetterTouchTools), it just launches Spotify, and then nothing happens.
_______

Also, to avoid creating another thread...
I'm trying to do the same thing for skipping songs—to open Spotify, press the next button, and then hide the app—but this doesn't work at all.

This is my script:

Applescript:

tell application "System Events"
   tell application "Spotify" to activate
   delay 0.3
   click at {689.48, 750.57}
   delay 0.3
   set visible of process "Spotify" to false
   delay 0.3
end tell

What am I doing incorrectly?

Offline

 

#2 2020-11-30 05:39:58 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1537

Re: Basic keystroke script works in Script Editor, but not when launched

1) Your first script replace with this:

Applescript:

tell application "Spotify" to playpause

2) Your second script replace with this:

Applescript:

tell application "Spotify" to next track

Last edited by KniazidisR (2020-11-30 05:42:16 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#3 2020-11-30 07:42:56 am

KevS
Member
Registered: 2017-05-23
Posts: 14

Re: Basic keystroke script works in Script Editor, but not when launched

KniazidisR wrote:

[...]

Those are much better. Thanks. However, the scripts work fine in the Script Editor, but when I try to launch them (with BetterTouchTools), nothing happens.

I think there is a setting preventing scripts from working correctly.
(Even though I've added BetterTouchTool and Spotify to Accessibility in "Security & Privacy.")

What do I need to make sure is set up for scripts to work?

Last edited by KevS (2020-11-30 07:43:17 am)

Offline

 

#4 2020-11-30 08:18:27 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 731

Re: Basic keystroke script works in Script Editor, but not when launched

KevS. I don't use BTT and instead use a somewhat similar utility called Fastscripts. To get it to work with GUI scripting in Catalina, I did the following in Security & Privacy:

* add Fastscripts to Accessibility
* add Fastscripts to Full Disk Access
* add System Events (which is found in /System/Library/CoreServices/) to Full Disk Access

I'm not sure if this will work but it's easy to try and is easily undone. Perhaps someone who uses BTT will be able to better help.

Last edited by peavine (2020-12-01 02:27:26 pm)


2018 Mac mini - macOS Catalina

Offline

 

#5 2020-11-30 08:34:19 am

KevS
Member
Registered: 2017-05-23
Posts: 14

Re: Basic keystroke script works in Script Editor, but not when launched

I was able to launch the scripts using another app (they all work now). The first time I ran them, an OS window appeared asking to allow it to control System Events, and it was added to "Automation" in "Security & Privacy."

There doesn't seem to be any "+" button or any other way to add apps, so that I can add BetterTouchTool, though...

Offline

 

#6 2020-12-01 02:00:54 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1537

Re: Basic keystroke script works in Script Editor, but not when launched

I don't know why you are so stuck with GUI scripting solution. In my opinion, it would be better if you in Security & Privacy would grant your application permission to control not System Events, but Spotify.

Last edited by KniazidisR (2020-12-01 02:02:20 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#7 2020-12-01 09:13:41 pm

KevS
Member
Registered: 2017-05-23
Posts: 14

Re: Basic keystroke script works in Script Editor, but not when launched

KniazidisR wrote:

I don't know why you are so stuck with GUI scripting solution. In my opinion, it would be better if you in Security & Privacy would grant your application permission to control not System Events, but Spotify.


I'll try to re-organize the settings to make it work.

Thanks for help, KniazidisR.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)