You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

My aplescript wont work!

I was trying to duplicate the box that says

in applescript. It says “Script Error. Can’t get button returned of {"Chrome"}.” Here’s the script:

display dialog "The developer of this app needs to update it to work with this version of macOS. Contact the developer for more information." with title "“PrankExport” needs to be updated." buttons {"Learn More...", "OK"}

if the button returned of the result is "Learn More..." then

choose from list {"Safari", "Chrome"} with prompt "Which app will you use to open?"

if button returned of the result is "Safari" then tell application "Safari" to open location "https://support.apple.com/en-us/HT208436"

else

tell application "Google Chrome" to open location "https://support.apple.com/en-us/HT208436"

end if

iMac 21.5″, macOS 10.15

Posted on Jul 25, 2020 3:41 PM

Reply
Question marked as Top-ranking reply

Posted on Jul 27, 2020 11:12 AM

That's because you're using 'Open Location', which is NOT a Google Chrome command. It's also not a Safari command.


Open Location is a standard addition - meaning it's handled outside of any application - in this case it's something the OS uses to decode the URL, find the appropriate handler application, and invoke it. In other words, if your default browser is set to Chrome, it will open in Chrome; if it's set to Firefox then it will open in Firefox. You can also pass it mailto:, ftp:, file:, or any other URL and it will (attempt to) handle it.


So whenever you use 'Open Location', your default browser is going to launch, which is why it appears to not work with Chrome.


It's actually a simple way to avoid the script having to know which specific app to target for common URLs.


If you want to specifically target Chrome, then you'll need to add Chrome-specific commands to get it to open a URL. Something like:


set theURL to "https://support.apple.com/en-us/HT208436"

tell application "Google Chrome"
	if windows ≠ {} then
		make new tab at the end of window 1 with properties {URL:theURL}
	else
		make new window
		set URL of (active tab of window 1) to theURL
	end if
	
	activate
end tell


Similar questions

3 replies
Question marked as Top-ranking reply

Jul 27, 2020 11:12 AM in response to Zurcrescred556

That's because you're using 'Open Location', which is NOT a Google Chrome command. It's also not a Safari command.


Open Location is a standard addition - meaning it's handled outside of any application - in this case it's something the OS uses to decode the URL, find the appropriate handler application, and invoke it. In other words, if your default browser is set to Chrome, it will open in Chrome; if it's set to Firefox then it will open in Firefox. You can also pass it mailto:, ftp:, file:, or any other URL and it will (attempt to) handle it.


So whenever you use 'Open Location', your default browser is going to launch, which is why it appears to not work with Chrome.


It's actually a simple way to avoid the script having to know which specific app to target for common URLs.


If you want to specifically target Chrome, then you'll need to add Chrome-specific commands to get it to open a URL. Something like:


set theURL to "https://support.apple.com/en-us/HT208436"

tell application "Google Chrome"
	if windows ≠ {} then
		make new tab at the end of window 1 with properties {URL:theURL}
	else
		make new window
		set URL of (active tab of window 1) to theURL
	end if
	
	activate
end tell


My aplescript wont work!

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.