Can I run a local AppleScript from a web page?

I am looking for a way to run a local applescript from a web page. Either from embeded code or by the script checking the page/url as it is loaded.

I know the browsers try to block interaction with the system as this is huge security hole for hackers. My intention is to have a small applescript that users can download “ this then acts as a bridge between the site and programs like suitcase, quark or indesign.

If it is not possible to talk to applescript directly from the page, can applescript keep an eye on safari? For instance, when safari loads a new page, the script checks the url or source and if there is an instruction there applies it.

Thanks for any help.

I dont know if I understand what you need. An idea is to make a script that runs through your email account. The people could go online and email you computer, which could trigger a script or app to start. I have home automation, so I have done this with some of my programs.

Here’s a way to run a script from a link.

Use a local file url like:

file:///Users/kel/Desktop/Test%20Folder/hello.app – the script

Safari won’t acknowledge a file like this (script) because it doesn’t know how to open it. Instead it reveals it on my system. I don’t know if it does this on your system. By revealing the item it couldn’t deal with, it opens the window that contains the item. So you can add a folder action to that folder and run the selected script. Here’s an example of the folder action:

on opening folder this_folder
tell application “Finder”
set the_sel to selection
end tell
set the_script to the_sel as alias
run script the_script
end opening folder

You might want to close the window.

gl,

Hi,

Wait, I found a bug with this on my system. If I hit the link to the local file, then later try to empty the cache, Safari quits. Wonder why it’s doing this.

gl,

Thanks, I’ll try kel’s approach but I really wanted to find something much simpler…

Not belittling my users but they won’t get around to setting up folder actions.

What I am really trying to write is a passive script that runs when it recieves an instruction from a web site.

eg.

I am developing a font based site with new search engines and thousands of fonts available.
When a user finds the font he wants I would like for them to click a button and the script tells suitcase to activate that font.

Sounds simple doesn’t it?

That’s why I was thinking along the lines of getting the script to run everytime safari changes a page.
or for the page to send a variable to the script.

Thanks again.

Mark

It’s good that the user has to do work. In fact, you can have the user run a script that sets up the folder action. It’s not good when the user has no interaction in this case.

Hi Kel, I agree with you to a point.

However the user does not have to configure the system when suitcase is installed. He just adds fonts and clicks them on or auto activates them through quark et al.

=> It’s not good when the user has no interaction in this case.

The user has lots of interaction,
Firstly to decide to download the script,
Secondly to decide when to have it running,
Thirdly to select which font to activate.

IE. This is totally at the users discretion unlike viruses/spam that tries to do something against yor will. I do not want to create a virus nor do I want to download any script not specifically asked for.

I will have a play with your suggestion to set-up a folder action. The main problem I can see is that the folder action will run on all downloads that safari does not recognise.

My intention is to empower the user and make it as easy as possible to use a site in a similar fashion to an application installed on the local system.

Hope this makes it clearer.

Thanks again for your input. Any more ideas?

Mark

Hi Mark,

I’m not feeling well, so took a while to understand.

You might use a script with an idle handler that checks the url. An idle handler has the form:

on idle
– statements here
return 2 – seconds
end idle

and is saved as a stay open script. The above script would return every two seconds and run. The above won’t do anything in the Script Editor. Your stements could maybe get the url or text of the page.

tell application “Safari”
set the_url to URL of front document
end tell

or

tell application “Safari”
set the_url to text of front document
end tell

The script could parse the url or text. Another idea might be to parse the source html or use a javascript to do something.

If the script finds something, then it could get the suitcase to activate the font.

There are many ways to go with this.

gl,

Use PackageMaker to package your products. Safari will automatically open .pkg files after downloading them so it’ll only take them a couple of clicks to install, and you can include preflight and postflight scripts to perform additional setup and configuration as appropriate. Since you’ve lots of similar items to package in the same way, you’ll want to set up a standard automated build process using shell scripts, etc, so see the packagemaker manpage for help with writing those.