On Dec 5, 2010, at 11:49 AM, Marconi wrote:
Given the quoted form of a posix path to a file, how do I get that item's Finder info structure so I can rename that file?
I have a script that gets the item info for files dropped onto the script and renames the file based on contents of that file. But each dropped file has a corresponding file with a similar name and a different suffix and I need to rename that file as well (based on the data in the original dropped ".txt" file).
Here is an example script that does (I think) something close to what you need ...
on open dropList
if (count items of dropList) ≠ 1 then return
-- items of dropList have <<class bmrk>>
set dropItem to (item 1 of dropList) as alias
--
tell application "Finder"
set itemName to (name of dropItem) as text
set itemExtn to (name extension of dropItem) as text
end tell
--
if itemExtn = "tex" then
set altExtn to "txt"
else if itemExtn = "txt" then
set altExtn to "tex"
else
return -- wrong extension or folder
end if
if itemName ends with ("." & itemExtn) then
(length of itemExtn) + 2
set itemName to text 1 thru -(the result) of itemName
end if
display dialog "Type a new name ..." default answer itemName
set newName to text returned of the result
--
tell application "Finder"
set itemCont to (container of dropItem) as alias
set name of dropItem to (newName & "." & itemExtn)
--
try
set dropItem to (item (itemName & "." & altExtn) of itemCont) as alias
on error
return -- item does not exist
end try
set name of dropItem to (newName & "." & altExtn)
end tell
beep
delay 1
end open
Notice that posix path is not used. You will need to change the extensions for your situation.