Jump to content
gr8

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!

 

Share this post


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

 

Edited by vitor

Share this post


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. 

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...