Jump to content

Script works in Script Editor but not in Alfred Workflow


gr8

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 post

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

 

Link to post
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 post

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...