Re: problem with paths [too well trodden]
Re: problem with paths [too well trodden]
- Subject: Re: problem with paths [too well trodden]
- From: Richard 23 <email@hidden>
- Date: Fri, 12 Jan 2001 01:40:22 -0800
>
if I pull the (path to scripting additions) outside of the tell finder
>
block it is fine but then the exists file is not going to work real
>
well... so why did this stop working?
The gods must be angry. There's more than one way to skin a cat but
every one I can think of is equally repulsive. But that's another topic.
There is another way to check for exists outside of a Finder tell block.
-- ---------------------------------------------------------
-- Preprocessed by Convert Script 1.0d2
-- ---------------------------------------------------------
on exists theFile
try
theFile as alias
theFile /= ""
on error
false
end try
return result
end exists
-- ---------------------------------------------------------
Also if you frequently use "path to" and would prefer a "path to"
rather than an "alias for" you can modify that as well:
-- ---------------------------------------------------------
-- Preprocessed by Convert Script 1.0d2
-- ---------------------------------------------------------
on path to theItem
continue path to theItem as string
end path to
-- ---------------------------------------------------------
while you're at it, you may as well fix some annoying misfeatures
like log statements, clipboard, speech commands clearing the result
variable.... Hey fellas, if you ain't going to return a result
then leave it alone!
-- ---------------------------------------------------------
-- Preprocessed by Convert Script 1.0d2
-- ---------------------------------------------------------
-- modifying command handlers to return a result can make
-- writing more compact scripts a simple as crashing Netscape!
-- ---------------------------------------------------------
set theValue to "boo"
if (set the clipboard to theValue) "" and beep and beep then ==>
display dialog (say (log {message: "this is a test"})) buttons ==>
{"Cancel", "So What", "OK"} default button 3 with icon -20024
return log {|user response|: result's button returned}
-- ---------------------------------------------------------
on say theMsg
continue say theMsg
return theMsg
end say
-- ---------------------------------------------------------
-- note: the weird return method is to allow messages to be
-- passed as a list of labelled values, stripping the labels
-- before the return, returning single items as...single items!
-- ---------------------------------------------------------
-- set {homer, curley} to log {homer: "d'oh", curley: "n'yuk"}
-- ---------------------------------------------------------
on log theMsg
continue log theMsg
return theMsg as list as item
end log
on set the clipboard to theValue
continue set the clipboard to theValue
return the clipboard
end set the clipboard to
on beep
continue beep
return true
end beep
-- ---------------------------------------------------------
-- sometimes this is useful too:
if noGood then set {theMsg} to {"Bummer", run script "error number -128"}
Stream of consciousness baby!