Error with AppleScript to Press Keys

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Error with AppleScript to Press Keys Wed Apr 05, 2023 12:09 am • by alexcr
I'm trying to replicate pressing "⌘⌃⌥C" on the keyboard (ignoring the quotation marks) via the following embedded AppleScript, with the trigger being a certain kind of file being added to a folder...

Code: Select all
tell application "System Events"
   keystroke "c" using {control down, option down, command down}
end tell


However, I'm receiving an error message from Hazel when I attempt to run this. Any advice on what I might be doing wrong?
alexcr
 
Posts: 7
Joined: Wed Apr 05, 2023 12:02 am

Re: Error with AppleScript to Press Keys Wed Apr 05, 2023 10:18 am • by Mr_Noodle
What is the error message you are seeing?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Error with AppleScript to Press Keys Wed Apr 05, 2023 5:05 pm • by alexcr
Mr_Noodle wrote:What is the error message you are seeing?


It's just a generic error message...

https://imgur.com/a/KxTsrhi
alexcr
 
Posts: 7
Joined: Wed Apr 05, 2023 12:02 am

Re: Error with AppleScript to Press Keys Thu Apr 06, 2023 10:26 am • by Mr_Noodle
Check the logs. Go to Help->View Logs and see if you can find more details of the error there.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Error with AppleScript to Press Keys Fri Apr 07, 2023 5:21 am • by alexcr
Mr_Noodle wrote:Check the logs. Go to Help->View Logs and see if you can find more details of the error there.


Thanks. Here's what I found, though I'm not sure what exactly it means...

2023-04-07 01:53:35.780 hazelworker[89451] [Error] AppleScript failed: Error executing AppleScript on file /Users/alexrosenfeld/Dropbox/My Mac (Alexs-MacBook-Pro.local)/Desktop/video-output-4749A26F-248F-483E-A450-9EBAB34F89CE.MP4.
2023-04-07 01:53:35.780 hazelworker[89451] OSAScript error: {
NSLocalizedDescription = "System Events got an error: hazelworker is not allowed to send keystrokes.";
NSLocalizedFailureReason = "hazelworker is not allowed to send keystrokes.";
OSAScriptErrorAppAddressKey = "<NSAppleEventDescriptor: [0x0,4e04e \"System Events\"]>";
OSAScriptErrorAppNameKey = "System Events";
OSAScriptErrorBriefMessageKey = "hazelworker is not allowed to send keystrokes.";
OSAScriptErrorMessageKey = "System Events got an error: hazelworker is not allowed to send keystrokes.";
OSAScriptErrorNumberKey = 1002;
OSAScriptErrorRangeKey = "NSRange: {0, 0}";
}
alexcr
 
Posts: 7
Joined: Wed Apr 05, 2023 12:02 am

Re: Error with AppleScript to Press Keys Fri Apr 07, 2023 9:29 am • by Mr_Noodle
That means you need to give Hazel permissions. Launch System Preferences/Settings and go to Security & Privacy. Select Accessibility and add/enable Hazel in that list. Also, check the Automation list.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Error with AppleScript to Press Keys Sat Apr 08, 2023 12:46 am • by alexcr
Mr_Noodle wrote:That means you need to give Hazel permissions. Launch System Preferences/Settings and go to Security & Privacy. Select Accessibility and add/enable Hazel in that list. Also, check the Automation list.


Thanks! I checked, and Hazel is already added and enabled, so why would I be getting this error message then? What is the Automation list?
alexcr
 
Posts: 7
Joined: Wed Apr 05, 2023 12:02 am

Re: Error with AppleScript to Press Keys Mon Apr 10, 2023 9:11 am • by Mr_Noodle
It's also in System Settings/Preferences in the same list with Accessibility.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Error with AppleScript to Press Keys Tue Apr 11, 2023 2:48 am • by alexcr
Mr_Noodle wrote:It's also in System Settings/Preferences in the same list with Accessibility.


I see. Thanks. I can confirm that Hazel has already been added and enabled for "System Events" in "Automation." So that doesn't seem to be the problem either. What am I missing?
alexcr
 
Posts: 7
Joined: Wed Apr 05, 2023 12:02 am

Re: Error with AppleScript to Press Keys Tue Apr 11, 2023 8:33 am • by Mr_Noodle
Can you post a screenshot of how it looks in the Accessibility settigns?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Error with AppleScript to Press Keys Tue Apr 11, 2023 7:47 pm • by alexcr
Mr_Noodle wrote:Can you post a screenshot of how it looks in the Accessibility settigns?


Here you go...

https://d.pr/i/R1s3Bf
https://d.pr/i/WR2OY0

I just noticed that in the accessibility settings (but not in the automation settings) there is an additional Hazel item, with a weird name, "86Z3GCJ4MF.com.noodlesoft.HazelHelper". I have not turned this one on, as I had already turned on the "Hazel" item, and also because I hadn't noticed this due to its name and am confused about what it is.
alexcr
 
Posts: 7
Joined: Wed Apr 05, 2023 12:02 am

Re: Error with AppleScript to Press Keys Wed Apr 12, 2023 9:12 am • by Mr_Noodle
Yes, enable that as well. It's horribly named because of Apple's "security" requirements. It really should be handled by enabling Hazel by itself but the OS is buggy in that regards and sometimes exposes these internal processes.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Error with AppleScript to Press Keys Wed Apr 12, 2023 11:25 pm • by alexcr
Mr_Noodle wrote:Yes, enable that as well. It's horribly named because of Apple's "security" requirements. It really should be handled by enabling Hazel by itself but the OS is buggy in that regards and sometimes exposes these internal processes.


Thanks for clarifying! I did this, and it's now working without any issues, as far as I can tell. Awesome. Much appreciated.
alexcr
 
Posts: 7
Joined: Wed Apr 05, 2023 12:02 am


Return to Support