Re: Dumb Finder scripting question
Re: Dumb Finder scripting question
- Subject: Re: Dumb Finder scripting question
- From: Ed Stockly <email@hidden>
- Date: Sat, 15 Dec 2007 11:46:19 -0800
>>Mark>>Incidentally, my choice of the word "munge" was nothing but
linguistic playfulness, and not in any way meant to be
disparaging. I have nothing against manipulating text. I didn't
ask the question because I thought it was hard, or because I was in
some way offended at the thought of having to do text manipulation
on the filename.
Well, that's the impression I got. You referred to TIDs the way my
teenagers refer to cleaning their rooms.
>>Mark>> If I have to fall back on using TID to split and rejoin
the name, OK, but I was thinking there
might be a way to take an alias, modify its target
>>Mark>>I was talking about modifying the properties of an alias
object in place, rather than coercing back to a string and then
back to an alias. Something like you can do with date objects -
set the properties of an object without having to turn it into a
number and then construct a new object from the new number.
OK, so a date object is simply a data type that exists in memory only
within the context of the script and is an AppleScript entity.
(AppleScript gets a date from a system and converts into its own
format it can easily manipulate).
An alias is a data type that is directly linked to an item on a
volume by the operating system's alias manager. It is an appleScript
representation of an operating system object. It must conform to the
rules of the alias manager and gets the benefit of the alias
manager's functions. (For example, if a user moves an alias after
your script has been compiled, even while your script is running, the
alias manager keeps track of it and your script can continue.)
A file path is just a string that references a file on a volume.
So, it sounds like you were hoping to use the finder to directly
manipulate the alias, a system object.
Clearly an AppleScripter is better off manipulating file path strings
and aliases rather than trying to directly manipulate aliases, even
it were possible.
>>me>>if you're referring to the finder "Exists" command, I think
you'll find coercing to alias a more reliable way to determine if
an item exists, and you don't need the Finder for that.
>>mark>>Well, I was already in a Finder tell block anyway, so I
don't think it hurts, and using exists let me avoid a try block,
which I feel would have overcomplicated the code for such a simple
problem.
Being in a tell block makes no difference. Issuing a command within
a tell block contains no less overhead than initiating a new tell
block, and being inside a tell block is no reason to not use the
simpler more reliable command. If the finder is the most reliable way
of doing something use it, otherwise don't. If the exists command or
your desired alias manipulation were the most reliable, do it that
way, if they're not, don't.
Going in and out of tell blocks is painless.
Plus, you don't have to go outside the tell block to manipulate
strings and aliases.
tell application "Finder"
try
set myPath to myPath as alias
end
end
Works just as well, just as reliably as
try
set myPath to myPath as alias
end
Plus, a simple try block carries no additional overhead.
>>From earlier> I know this was a pretty basic question, Finder-
scripting-wise, but I thought I had enough of a rep on here to get
*some* benefit of the doubt as far as overall cluefulness.
Hey Mark, don't take any of these answers personally. Always remember
we never hear from most subscribers to this list, on the list. Many
of them lurk and learn from others questions and answers, plus, we're
always suggesting people search the archives when they have questions.
This is a public forum, we should try to both answer an individual's
questions and provide complete answers to help others who may come
across similar questions in the future.
ES
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden