Boilerplate 'run' handler for droplets
Boilerplate 'run' handler for droplets
- Subject: Boilerplate 'run' handler for droplets
- From: Brennan <email@hidden>
- Date: Wed, 13 Nov 2002 22:35:42 +0100
Hi folks,
Inspired by a recent post on this list, I'm working on a robust 'run' handler for droplets. The idea is that when you double-click a droplet, you might be wanting to edit it, but OTOH you might be wanting to run it. However, if it's actually running from a script editor application you almost certainly want to run it. (Exceptions, exceptions).
Here's what I have so far:
on run
set prmpt to "Choose a file or edit the script?"
set b to {"Choose...", "Edit", "Cancel"}
set dr to (display dialog prmpt buttons b default button 1)
set br to (dr's button returned)
if br is "Edit" then
set myContainer to (path to me)
set inf to (info for myContainer)
set fcr to file creator of inf
if fcr is in {"aplt", "dplt"} then -- running as an applet or droplet
tell application "Finder" to open myContainer using application file id "ToyS"
else if fcr is in {"ToyS", "VIZF", "asDB", "WILD"} then -- running in a known script editor application
-- (Script Editor, Smile, Script Debugger, Hypercard).
-- Others I don't know the creator code of; Applescript Studio?, Scripter?... others?)
my abortWithAlert("Script is already running in " & name of inf & "!")
else -- some unknown script runner. What to do?
my abortWithAlert("Script running in some unexpected app!")
end if
return
else if br is "Choose..." then
set f to (choose file) -- throw up a file selector dialog (standard additions OSAX)
open ({f})
end if
end run
on abortWithAlert(str)
beep
display dialog str buttons {"Rats"} default button 1 giving up after 10
error number -128 -- abort entire script
end abortWithAlert
-- insert 'open' handler here...
OK, I should probably check which app it's running in BEFORE offering to edit the thing, but I'll get to that later. What I'm interested in right now, is the creator codes for Applescript Studio and Scripter. I'm also unsure whether "VIZF" is still the creator code of Script Debugger. (I only had an old copy to check with).
Other suggestions for improvements are welcome, like what to do if 'path to me' points to an unknown creator type. (Example: In OSA menu, 'path to me' points to the script, which might be a compiled script, which has creator "ToyS", so the script will think it is running in "ToyS". I will need to fix this). I'm also working in OS9, so there may be some OSX-specific things I am overlooking. Creator codes are being phased out, aren't they? (To be replaced by something other than DOS-style file extensions, I hope. Well, Apple DID hire some Be engineers to work on the file system...).
Thanks for any help, and I hope others will find a use for this handler in their droplets.
Brennan
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.