Jump to content

AppleScript generating -4960 error


Recommended Posts

I have an AppleScript that I am trying to run in Alfred

 

on run 
	
	set theQuery to "{query}"
	set theFileList to {}

	repeat with aFile in paragraphs of theQuery
		copy (POSIX file aFile) to the end of theFileList
	end repeat

	tell application "Freeform"
	
		activate
	
		repeat with aFile in theFileList
			set the clipboard to aFile
			tell application "System Events" to keystroke "v" using command down
		end repeat
	
	end tell

end run

 

This runs fine in Script Debugger (I hardcore the query) but when I try to run it in a Run Script object I get

 

[21:34:28.807] ERROR: Anagram Tiles[Run Script] 471:477: execution error: An error of type -4960 has occurred. (-4960)

 

I am assuming that it is a Privacy and Security issue. Alfred doesn't appear to have the correct permissions but it is also not asking for them.

 

I have tried to reset the permissions and then re-enable them but I still get the error.

 

I tried putting the code into two try blocks but it doesn't generate any errors which makes me think that it is a Permissions issue.

 

Anyone had a similar problem? 

CleanShot 2023-03-02 at 21.25.40@2x.jpg

CleanShot 2023-03-02 at 21.25.52@2x.jpg

Link to comment
6 hours ago, pixelgeek said:

Alfred doesn't appear to have the correct permissions but it is also not asking for them.


Apps don’t ask for permission, macOS does when you try to do the thing. The distinction matters because bugs or decisions in macOS may prevent the dialog from showing (e.g. some permission prompts only show up once).

 

But in this case I suspect the script is failing before it even gets to that part.

 

6 hours ago, pixelgeek said:

I am assuming that it is a Privacy and Security issue.


Remember you’ve changed your code before sending it to Alfred. Assume first the error might be there. From reading the code, I guess you’re passing a multi-line string which is then being replaced. I can imagine that being the cause.

 

Use argv instead of {query} in scripts. And don’t split the input in your script, do it before the arguments arrive. That will make it more robust, easier to debug, and more portable.

Link to comment
2 hours ago, vitor said:

Remember you’ve changed your code before sending it to Alfred.

 

Actually I have not 🙂 I took the output from the Debugger in Alfred and pasted that {query} data into Script Debugger and assigned it to the same variable. 

 

After that the code is copied directly. I was hoping to avoid having to change the code at all. 

 

I will change to using args and test that

 

2 hours ago, vitor said:

But in this case I suspect the script is failing before it even gets to that part.

 

That was my thought as well. Which is why I added the try/onerror code. It didn't generate any errors though. 

 

An interesting problem

Link to comment
8 hours ago, Stephen_C said:

I haven't really thought this through in detail (sorry: horribly early in the morning here!) but wonder if this post from Vitor (about splitting variables in AppleScript) helps. I had a slightly similar problem which was resolved by that post.

 

Thanks. I will check that out

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