2011/05/29

Embed AppleScripts in a MediaWiki page

You can embed an AppleScript in a MediaWiki page if you insert the script as the URL in a proper HTML link. Particularly, the HTML link syntax looks like this:
<a href="URL">Link text</a>
The AppleScript code should be converted in a format which is compatible with HTML URLs. For example, each space in the script should be replaced by the string %20, each tab by %09 and each enter by %0D. Moreover, the "applescript://" URL scheme will be used and the whole link should be within <html>, </html> tags.   Fortunately the whole conversion can be done automatically by an AppleScript or using the freeware AppleScriptHTML app.

Finally, raw HTML code is not allowed by default in a public wiki for security reasons but if you maintain a private wiki you can permit it by setting
$wgRawHtml = true;
in the LocalSettings.php file.

For example, suppose you want to embed the following AppleScript
tell application "Finder"
    open (alias "MBSystem:Users:MB:Downloads:")
end tell
which opens the "Downloads" folder in a Finder window. Then, you should write the following code in a MediaWiki page:
<html>
<a href="applescript://com.apple.scripteditor?action=new&script= tell%20application%20%22Finder%22%0D
%09open%20(alias%20%22MBSystem%3AUsers%3AMB%3ADownloads%3A%22)%0D
end%20tell"l>MBSystem:Users:MB:Downloads:</a>
</html>
and you will see the link, after saving the page.


Afterwards, every time you click the link an AppleScript editor window opens with the AppleScript code inside it, as is shown in the next image.

Now, you may press cmd + R (executes the script), cmd + W (closes the window) and cmd + D (without saving)!

In my next post, I will present how you can create automatically HTML links to local files and folders, with AppleScript code inside them, which can be embedded in a MediaWiki page.

No comments: