Skip to content

Instantly share code, notes, and snippets.

@Lockyc
Forked from georgebrock/Info.plist
Created September 4, 2023 06:34
Show Gist options
  • Select an option

  • Save Lockyc/8cb68ee11a9d22b40df4f5257b71bc50 to your computer and use it in GitHub Desktop.

Select an option

Save Lockyc/8cb68ee11a9d22b40df4f5257b71bc50 to your computer and use it in GitHub Desktop.
AppleScript to handle URLs

Follow these instructions to create an AppleScript App that can be used to open URLs, e.g. from Choosy.

  1. Open Script Editor (in /Applications/Utilities).
  2. Write a script with an on open location handler (see example.applescript).
  3. Save the script as an application (select "Application" from the file format dropdown in the save dialog in Script Editor).
  4. Edit the application's Info.plist file to add a CFBundleURLTypes section, indicating it can handle HTTP URLs (see Info.plist). If the app is at ~/Applications/MyApp.app then the Info.plist will be at ~/Applications/MyApp.app/Contents/Info.plist.
  5. Test your application from the command line using open -a ~/Applications/MyApp.app http://www.example.com
  6. Update the AppleScript to do something useful with the URL (the do shell script command might be useful if you want to avoid writing more AppleScript).
  7. ?
  8. Profit.
on open location this_URL
display alert this_URL
end open location
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- ... -->
<!-- Add this section: -->
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>HTTP URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>http</string>
<string>https</string>
</array>
</dict>
</array>
<!-- End of what needs adding -->
</dict>
</plist>
@Lockyc
Copy link
Author

Lockyc commented Sep 4, 2023

To create copy to clipboard browser use

on open location this_URL
	set the clipboard to this_URL
	display notification this_URL with title "Copied to Clipboard"
end open location

Note: without notification it will always show dialog "Press run to run this script..."

@Lockyc
Copy link
Author

Lockyc commented Sep 4, 2023

CleanShot 2023-09-04 at 16 52 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment