Jump to content

[SOLVED] Applescript to play a song fails

Recommended Posts

I am using the 'Play song' from iTunes as a workflow. The debugger shows"


[2019-02-28 17:37:53][ERROR: input.scriptfilter] Code 1: filters/playsong.applescript: execution error: Not authorized to send Apple events to iTunes. (-1743)



I know this is an issue with Mojave and the new 'sandbox' security bubble they put around interacting with the OS; I just don't know how to give it access. Alfred is already enabled in the seurity section.


Any thoughts? 

SS  2019-02-28 at 5.45.44 PM.png

SS  2019-02-28 at 5.47.20 PM.png

Edited by billiesoniq
Link to comment
  • vitor changed the title to [SOLVED] Applescript to play a song fails
  • 10 months later...

What do you do when trying to use iTunes.app in Catalina instead of Music.app? (For those of us who won't give it up: Retroactive)


I assume there's a way to force / trigger Alfred to ask for permission for other various apps (such as iTunes.app)? Sadly SizzlingKeys has still been an up and down ride (sometimes won't work at all) and so I'm left trying to use something like http://www.packal.org/workflow/itunes-seeking.

Link to comment

Well I think that's what I essentially did - the problem, however, is that the automation permission is not being set in Preferences... only for Music.app (see this, Music.app is the only one and I can't add more manually).  I'm trying to figure out allow that script I noted above (com.tylast.itunesseeking) to actually execute. Note the screencast here wherein I show the hotkey activation of the script with the error / problem results below in the debug panel and then the source that's being used at the end:



And here is the skip-back script I noted from above here:

on alfred_script(q)
  tell application "iTunes"
	if player state is playing then
		--get the current track time:
		set currTime to get player position
		if currTime < 10 then
			--go to start of the track:
			set currSkip to 0
			--otherwise, skip backwards 
			set currSkip to currTime - 5
		end if
		set player position to currSkip --skip to new position
	end if
  end tell
end alfred_script



Link to comment

I don't know anything about Catalina (I don't have it and have no intention of installing it), but you shouldn't use "Run NSAppleScript". Put your scripts in a regular Run Script action with Language = /usr/bin/osascript (AS) instead.


Run NSAppleScript behaves weirdly sometimes, and it blocks Alfred, too. Don't use it unless you have a good reason to.

Link to comment

So you're saying that I should set up a new workflow that uses "Run Script" instead of "Run NSAppleScript"? So to do the following steps:

1) Workflows

2) Click "+" -> "Blank Workflow"

3) "[+]" (Set up Alfred Remote pages for this project)

4) "+" ("Add Remote Page")

5) Assign title, etc.

6) at grid, click "+" square and "Run Script" from menu.

7) select "/usr/bin/osascript (AS)" & insert script...


Link to comment
  • 1 year later...

I've noticed that `Run NSAppleScript` is faster than the recommended use of `/usr/bin/osascript`.  Unfortunately things have gotten weird in Big Sur where after I did a reset of `tccutil` permissions across the board Alfred no longer executes NSAppleScript due to a permission error.  I see repeated recommendations to NOT use it... but I WANT to use it and would like to understand how to make it work again and get macOS to prompt for acceptation of permission.  Clearly it works somehow as it did up until I reset things, so... what's the magic sauce to make it work when we want to make it work?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...