Re: pass filenames to an application
Re: pass filenames to an application
- Subject: Re: pass filenames to an application
- From: "Mark J. Reed" <email@hidden>
- Date: Tue, 31 May 2005 21:01:53 -0400
Other folks have posted some solutions, but I'm going to chime in with some exposition.
1. In a command like this:
select
(every file of folder theItem whose name begins with "AS ")
there's the command, or verb ('select'), which tells the app
what to do, and then there's the (list of) thing(s) to do it to. A
chunk of AppleScript which represents a thing or a list of things is
called an "_expression_", and the value of an _expression_ can be stored
for later use inside a named container called a "variable", like so:
set name of variable to _expression_
For example, after this statement:
set theFiles to (every file of folder theItem whose name begins with "AS ")
You can then use "theFiles" anywhere that expects a list of Finder items, like this:
tell application "Finder" to select theFiles
2. The way AppleScript passes files and folders around is not by name,
but by reference. Things like BBEdit's "open" action expect a list of
aliases,
not filenames. These aren't the same thing as Finder aliases, but the
idea is similar: little widgets that let you get at the file they point
to directly, without having to parse a pathname.
3. What the Finder gives you back when you ask it for things like the
above isn't a list of AppleScript aliases; it's a list of Finder items,
which includes all the stuff the Finder knows about them that
AppleScript couldn't care less about. So you can't just tell BBEdit to
open theFiles after the assignment above. You have two options:
3a. First turn it into a list of AppleScript aliases, which the
coercion "as alias list" will do for you; this is the most general
solution, since you're left with a list of values that any AppleScript
function to deal with.
3b. But for your particular problem - opening them in an application -
you can also use the list as-is by telling the Finder to open the items
using the other application, rather than scripting the target app
itself.
4a. One problem with 3a is that there's a bug in AppleScript - if
there's only one item in a list, "as alias list" returns just that
alias by itself, not as a list (there's a difference between a bare
item and a list containing a single item). To get around this you have
to either explicitly check for the condition that the list has only 1
element, or else you can trap the error that happens when you try to
get the first item of a non-list, and fix it then.
Put it all together and you end up with the solutions proffered so far.
HTH.
On 5/31/05, dkd brain <email@hidden> wrote:
I am trying to do something that *should* be relatively simple, I want
to grab a bunch of files (whose names start with the same string) in an
arbitrary folder and open them in BBedit....
I can figure out how to identify these files, but can't seem to pass
the filenames back to BBedit
i.e. here is the finder part
set theItem to (choose folder) as string
tell application "Finder"
select
(every file of folder theItem whose name begins with "AS ")
end tell
so, my little finder snippet correctly identifies the files I want to
send to BBedit, but I can't figure out how to get these filenames into
a bbedit tell statement
i.e.
tell application BBEdit
open <filenames>
end tell
thanks for any advice....
_______________________________________________
Do not post admin requests to the list. They will be ignored.
email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden