I have a script which runs in a macOS Service. It needs to run in the user’s choice of web browser. This is the relevant part of the script:
set app_name to short name of (info for (path to frontmost application))
if app_name is "Safari" then
using terms from application "Safari"
tell application app_name
set video_URL to URL of current tab of first window
end tell
end using terms from
else if app_name is "Firefox" then
tell application app_name to activate
tell application "System Events"
keystroke "l" using command down
keystroke "c" using command down
end tell
delay 0.5
set video_URL to the clipboard
else if app_name is "Opera" then
tell application app_name
set video_URL to URL of front document as string
end tell
else if app_name is "Google Chrome" then
using terms from application "Google Chrome"
tell application "Google Chrome"
set video_URL to URL of active tab of front window
end tell
end using terms from
end if
I don’t have Opera or Chrome installed. When I run the service I always get a “Where is Google Chrome?” dialog. I never get a similar dialog for Opera (I don’t remember ever having it installed).
I have tried various ideas mentioned on MacScripter and StackOverflow including: adding a “using terms from” block; adding a “try/end try” block; changing from app “short name” to “bundle identifier”; changed test from “Google Chrome” to “Chrome”. Nothing I’ve tried has worked. I always get the “Where is” dialog.
Is there a way of suppressing that “Where is…” dialog ?
set app_name to short name of (info for (path to frontmost application))
if app_name is "Safari" then
set videoURL to run script "
tell application \"Safari\"
return URL of current tab of first window
end tell"
else if app_name is "Firefox" then
tell application app_name to activate
tell application "System Events"
keystroke "l" using command down
keystroke "c" using command down
end tell
delay 0.5
set video_URL to the clipboard
else if app_name is "Opera" then
set videoURL to run script "
tell application \"Opera\"
return URL of front document as string
end tell"
else if app_name is "Chrome" then
set videoURL to run script "
tell application \"Google Chrome\"
return URL of active tab of front window
end tell"
end if
Yes, and using “use terms from” is a bit pointless if the app is not installed. I did test a try block in various combinations (just not shown in my example code above). I think the “Expected end of line but found property” error still appeared and prevented compilation. Anyway, I’ll give it a try.