Applescript and "folder of file"

4 posts / 0 new
Last post
Tom Owad's picture
Offline
Last seen: 1 day 4 hours ago
Joined: Dec 16 2003 - 15:14
Applescript and "folder of file"

I'm working on the below Applescript to rename documents. (Note that I don't know how to program in Applescript.)

The script chokes on the line:

set pFolder to folder of file inName of startup disk

Telling me it can't find the document I've specified. But if I drag and drop the document "image.1.tiff" it specifically tells me:

Can't get file "image.1.tiff" of startup disk.

Any thoughts?

<br />
tell me to open {(choose file)}</p>
<p>on open (docList)<br />
--<br />
tell application "Finder"<br />
repeat with currItem in docList<br />
set theName to the name of currItem<br />
tell me to replace(theName)<br />
set the name of currItem to the result<br />
end repeat<br />
end tell<br />
--<br />
end open</p>
<p>to replace(inName)</p>
<p>set pFolder to folder of file inName of startup disk</p>
<p>set oldDelims to AppleScript's text item delimiters<br />
set AppleScript's text item delimiters to {"."}<br />
set wholeName to inName<br />
set numName to second text item of wholeName<br />
set numName to numName * 2<br />
set AppleScript's text item delimiters to oldDelims<br />
set prefix to "image"<br />
if numName < 10000 then<br />
set prefix to prefix & "0"<br />
end if<br />
if numName < 1000 then<br />
set prefix to prefix & "0"<br />
end if<br />
if numName < 100 then<br />
set prefix to prefix & "0"<br />
end if<br />
if numName < 10 then<br />
set prefix to prefix & "0"<br />
end if<br />
set outName to prefix & numName & ".tiff"</p>
<p>return outName<br />
end replace<br />

rael9's picture
Offline
Last seen: 13 years 6 months ago
Joined: Dec 26 2003 - 16:21
wrong variable

You are trying to find the folder of a string, not a file. The variable inName is just a string containing the name of the file, not a pointer to the file itself. If you want to get the containing folder of the currently selected file, you need to do a:

set pFolder to the folder of currItem

in the on open statement. Then you can do whatever you want with the folder. What are you going to do with the folder, anyway?

Tom Owad's picture
Offline
Last seen: 1 day 4 hours ago
Joined: Dec 16 2003 - 15:14
That works. Thanks! I'm w

That works. Thanks!

I'm writing a script (actually, cobbling together pieces of other people's scripts) to renumber files after they've been scanned. I wanted to know the parent folder so I could count the items in it, so I could reverse the numbering of the documents.

BDub's picture
Offline
Last seen: 11 months 4 weeks ago
Joined: Dec 20 2003 - 10:38
Cobbling Together

Ah, cobbling together what others have done so that you can get something done yourself. The beauty of open source.

I hope you'll be posting that script.

Log in or register to post comments