2

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

  • This is done for security reasons as anything in your browser can just open a URL, which means it could run arbitrary code. – 0942v8653 Feb 12 '15 at 2:55
  • Are you saying that what I am trying to do is impossible ? correct ? – iori Feb 12 '15 at 2:56
  • No actually it is possible, just a bad idea :) You'd have to make your own url scheme to run it. – 0942v8653 Feb 12 '15 at 2:57
  • I am totally with you. I am 100% aware of that, but for the sake of getting this working, do you know how to make this work ? :D – iori Feb 12 '15 at 2:58
  • 1
    There was definitely an app that let you do this, but I can't find it... – 0942v8653 Feb 12 '15 at 3:07
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .