Apple script and access permission

Hey everyone,

that's my first post 🐣

I'm trying to create a services that lets me add highlighted text into an existing note on the notes app using the keyboard shortcuts control+W and also have it in show up under the services menu. I think the script itself (attached below) is working.
  • when I try to use it outside of automator I'm getting this access permission error :


The action “Run AppleScript” encountered an error: “System Events got an error: Automator workflow Runner (WorkflowServiceRunner, WIDK) is not allowed to send keystrokes” 


  • the services isn't showing up in the right click menu. the first script I created using automator actually added the services to the service right click menu but any it disappeared and I don't seem to be able to add new services.

  • when I open automator after saving and closing it, I can't locate the services I saved, it's not showing up in the finder window of existing services.

  • I've tried using JavaScript to do this but it's was impossible to figure out my way around the retrieval of a specific note based on it's name so I'm using apple script :

Code Block
on run {input, parameters}
(* https://www.macosxautomation.com/applescript/notes/02.html *)
(* https://apple.stackexchange.com/questions/271161/how-to-get-the-selected-text-into-an-applescript-without-copying-the-text-to-th *)
-- Back up clipboard contents:
set savedClipboard to the clipboard
-- Copy selected text to clipboard:
tell application "System Events" to keystroke "c" using {command down}
delay 1 -- Without this, the clipboard may have stale data.
-- remove formmating of the selected text that was copied onto the clipboard
-- and set it to a temp var called noteHTMLText whice later be
-- concatnted onto the body of the note
set noteHTMLText to "<pre style=\"font-family:Helvetica,sans-serif;\">" & ¬
(the clipboard as Unicode text) & "</pre>"
-- Restore clipboard:
set the clipboard to savedClipboard
tell application "Notes"
tell account "iCloud"
tell folder "Notes"
set currentBody to get body of note "WIDK"
set body of note "WIDK" to currentBody & noteHTMLText
end tell
end tell
end tell
beep 2 --https://stackoverflow.com/questions/21503589/play-a-sound-when-applescript-is-done
return input
end run



Thank you for the help,
Daniel
Apple script and access permission
 
 
Q