Applescript and "folder of file"

3 replies [Last post]
Tom Owad's picture
Offline
Joined: Dec 16 2003
Posts: 2460

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 />

__________________

Admin

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rael9's picture
Offline
Joined: Dec 26 2003
Posts: 215
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?

__________________

James M. Baker
----------
Computer Nerd
----------
[url=http://rael.webhop.org"]My site[/url]

Tom Owad's picture
Offline
Joined: Dec 16 2003
Posts: 2460
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.

__________________

Admin

BDub's picture
Offline
Joined: Dec 20 2003
Posts: 706
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.

__________________

"There is going to be a future: let's chase it until it kills us." - Spider Robinson