• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Given a POSIX Path...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Given a POSIX Path...


  • Subject: Re: Given a POSIX Path...
  • From: Luther Fuller <email@hidden>
  • Date: Sun, 05 Dec 2010 17:06:57 -0600

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.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Given a POSIX Path... (From: Marconi <email@hidden>)

  • Prev by Date: Re: Given a POSIX Path...
  • Next by Date: Re: Given a POSIX Path...
  • Previous by thread: Re: Given a POSIX Path...
  • Next by thread: Finder error problem?
  • Index(es):
    • Date
    • Thread