How to embedded apple script in a link in HTML

applescripthtml

I tried to embedded apple script in a link in HTML, but all it does is brought up the Apple Script Editor Application with profiled script in it.

I want it to execute after I click on the link – so I don't have to press the play button.

Can someone help me fix this real quick ?

link.html

<a href = " 

applescript://com.apple.scripteditor?
action=new&script=

tell application %22Safari%22%0D%09
make new document with properties {URL:%22https://www.google.com%22}%0D%09 

end tell "> 

Click me to run the script ! 

</a>

Result:

enter image description here

Best Answer

The app is called LinCastor. (It can also be installed with homebrew cask if you have it.)

First click "add new scheme" in the bottom left of the main window, then change the title to whatever you like and the "scheme(s)" to x-applescript-runner.

Change the "handler" below from AppleScript to Shell, and paste this code in:

#!/usr/bin/env python

THE_PASSWORD = 'secret'

import os
import urlparse
import subprocess

params = urlparse.parse_qs(os.environ["URL_QUERY"].lstrip('?'))

password = params['password'][0]
script = params['script'][0]

if password == THE_PASSWORD:
    subprocess.call(['osascript', '-e', script])

Hit "Save and Activate", then test it with this url:

x-applescript-runner://?password=secret&script=display%20dialog%20%22hello%22%0A

Obviously you'll want to change the password from secret to something better like V2VkIEZlYiAxMSAyMjo0MjozOSBFU1QgMjAxNQo= (but not that either!). The password should make it slightly more secure, but of course anyone who sees your URL will still be able to run whatever they want with a URL.