Can't get filename/path from alias list

First off, let me say, I'm a complete AppleScript newbie, but not new to programming.
I'm trying to automate the creation of an album in iPhoto after Image Capture triggers my AppleScript via the "Automatic Task" feature. It appears that Image Capture passes an alias list to the script, but I'm having trouble accessing the individual filenames/paths in the list.

My current script looks like this:

-- Image Capture to iPhoto Handoff
-- adding folder name extractions
on open filesfromcamera

set pathstring to "Paths are:" & return

tell application "Finder"
repeat with thisalias in filesfromcamera
set myfile to the original item of alias thisalias
set pathstring to (pathstring & the name of myfile & return)
end repeat

display dialog pathstring

end tell

tell application "iPhoto"
import from filesfromcamera to album "test" without force copy
end tell
end open

When I use the script as shown above, I get the error "Can't make some data into the expected type" If I remove the "alias" coercion from the line "set myfile to the original item of alias thisalias" I get the error "Can't make <<class orig>> of alias "MacHD:Test:Pictures:pic1.jpg". If I try to just get the name of "thisalias" directly, I get the same error.

Perhaps it's not really an alias list I'm getting from Image Capture? However, if I don't to do any processing on "filesfromcamera" and pass that on to iPhoto, the import works just fine, so I know it's some sort of valid list.

My ultimate goal is to parse the pathname so I can use the name of the folder containing the images as the name of a new album in iPhoto.

Tried to find solution in past posts, but people using similar syntax all seem to get results they expect.


iMac 24" Mac OS X (10.4.9) 1 GB RAM

iMac 24", Mac OS X (10.4.9), 1 GB RAM

Posted on May 27, 2007 8:37 AM

Reply
2 replies

May 27, 2007 10:09 AM in response to jvolino

Your problem lies entirely in the line:

>set myfile to the original item of alias thisalias

There are two kinds of 'alias' in the Mac world - there's the alias used by the Finder, which is a pointer/shortcut/link to some other file, and there's the alias used by AppleScript to indicate a generic disk object (file, folder, etc.).

They are both file related, they have identical names, but they are completely different.

The 'original item' command relates ONLY to Finder aliases and is used to resolve the alias to find the real file it points to.

Your script however, is not using Finder aliases, so you can drop this entire line - it isn't needed. (FWIW I've been using AppleScript for years and I don't think I've ever used the 'original item' command in a real script.)

So now, coming to the part where you want to extract the file name from the alias, you can use the 'info for' command:

<pre class=command>repeat with thisFIle in filesfromcamera
set fileInfo to info for thisFile
set filename to name of fileInfo
set pathstring to pathstring & filename & return
end repeat</pre>

Now, as for using the folder name to determine the album, the easiest way is to ask the Finder:

<pre class=command>tell application "Finder"
set foldername to (get name of (container of myFile))
end tell</pre>

May 28, 2007 7:08 AM in response to Camelot

Thank you, Camelot. Indeed, I was a bit confused by the dual-use of the term "alias." I had originally been trying to get the name of "myfile" directly, but got errors about the object not being available and assumed that was because aliases (in the Finder shortcut sense) wouldn't return that property, when really I hadn't been "telling" Finder, so it's dictionary wasn't available. After I fixed the "tell" problem, I was still chasing aliases.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Can't get filename/path from alias list

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.