gr8 Posted April 13, 2017 Share Posted April 13, 2017 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
gr8 Posted April 13, 2017 Author Share Posted April 13, 2017 PS: Using Alfred 2.8.8 with Powerpack. Link to comment
vitor Posted April 13, 2017 Share Posted April 13, 2017 (edited) 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 April 13, 2017 by vitor gr8 1 Link to comment
gr8 Posted April 18, 2017 Author Share Posted April 18, 2017 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now