Jump to content

Script works in Script Editor but not in Alfred Workflow


Recommended Posts

Why would this script throw an error when used in an Alfred workflow but work when launched in Script Editor?

 

-- from https://gist.github.com/sillygwailo/1236890
on alfred_script(q)
property theURL : ""
tell application "Safari"
	set theURL to URL of current tab of window 1
end tell

tell application "Google Chrome"
	if (count of (every window where visible is true)) is greater than 0 then
		tell front window
			make new tab
		end tell
	else
		make new window
	end if
	set URL of active tab of window 1 to theURL
	activate
end tell
end alfred_script

The error it throws in the debug console is:

 

Quote

 

[ERROR: alfred.workflow.action.applescript] {

    NSAppleScriptErrorBriefMessage = "Expected \U201cend\U201d but found \U201cproperty\U201d.";

    NSAppleScriptErrorMessage = "Expected \U201cend\U201d but found \U201cproperty\U201d.";

    NSAppleScriptErrorNumber = "-2741";

    NSAppleScriptErrorRange = "NSRange: {72, 8}";

}

 

 

See also here http://snpy.in/nRniak

 

Sorry for the n00b question.

 

Thanks for your help!

 

Link to comment

Are you using a Run NSAppleScript? Don’t. Use instead a Run Script with /usr/bin/osascript (AS) as the Language. There are also some unnecessary things in your code (like property theURL : "") and other things could be made shorter. Try this:

 

tell application "Safari" to set theURL to URL of front document

tell application "Google Chrome"
	if (count of (every window where visible is true)) is greater than 0 then
		tell front window to make new tab
	else
		make new window
	end if
	set URL of active tab of front window to theURL
	activate
end tell

 

Edited by vitor
Link to comment
On 4/13/2017 at 6:47 PM, vitor said:

Are you using a Run NSAppleScript? Don’t. Use instead a Run Script with /usr/bin/osascript (AS) as the Language

 

That did it! Thank you very much, I'll remember this for the future. 

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