• 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
Help -- going posix space crazy
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help -- going posix space crazy


  • Subject: Help -- going posix space crazy
  • From: Marc Glasgow <email@hidden>
  • Date: Fri, 21 Feb 2003 06:08:29 -0500

The following works as long as the path doesn't have any spaces in the names -- then add spaces, and I get a format error for the mv command. Any insight appreciated. Complete text of the minimized testing script is at:
http://www.cyberpoet.net/as/030220help.txt


my TermRename(TheFileChoosen, TheEnteredName, OurSwitch)
----------------+----------------+----------------+---------------- +----------------+
-- HANDLER  TermRename
-- Purpose: renames a file to a new name
-- Expected Input: -- string or alias of path & file name (colon delimited) to be renamed
-- string or alias of path & file name (colon delimited) or -- just file name to be renamed to
-- boolean, whether name to be changed to includes path (true = includes path)
-- Returns Output: NONE
-- Calls NO other handlers
-- Calls 1 Application: Terminal
----------------+----------------+----------------+---------------- +----------------+
local PosixOldFile -- The passed in old file path/name as a Posix path & file name
local PosixNewFile -- The passed in new file path/name as a Posix path & file name
local PosixLength -- the length of Old file & path name as a posix path
local GenericLoopFlag -- boolean, to loop or not to loop?
local GenericCharCount -- character index from right to left (back to front) of Posix path
local NewPosixPath -- the path to the old filename sans the filename itself
-- could be done with TIDs I think, if I understood them better.
local CurrentChar -- character to test, as text

on TermRename(OldPathFileName, NewPathFileName, Switch)

set PosixOldFile to the POSIX path of OldPathFileName
display dialog PosixOldFile as text
if not (Switch) then -- if only filename has been passed in (no path)
set PosixLength to the length of (PosixOldFile as text) as integer
set GenericCharCount to 0
set GenericLoopFlag to true as boolean
repeat while GenericLoopFlag
set GenericCharCount to GenericCharCount + 1
set CurrentChar to (character (PosixLength - GenericCharCount) [con't]
of (PosixOldFile as text))
if CurrentChar = "/" then

set GenericLoopFlag to false as boolean

set NewPosixPath to characters 1 thru (PosixLength - [con't]

GenericCharCount) of (PosixOldFile as text) as text

display dialog "Just the Posix Path:" & return & NewPosixPath

set PosixNewFile to ((NewPosixPath) & (NewPathFileName)) as text

display dialog "New Posix Path & File Name:" & return & PosixNewFile

-- THE DISPLAY DIALOG ABOVE DISPLAYS CORRECTLY, BUT
-- I SUSPECT THE 'set PosixNewFile' LINE ABOVE IS LOSING
-- THE DELIMITERS FOR SPACES....

end if
end repeat


else -- if full path & filename has been passed in

set PosixNewFile to the POSIX path of NewPathFileName
-- haven't tested this portion yet, but suspect I will get an error trying
-- to point at a file that doesn't exist yet (even if it will become a file
-- through the renaming process).
end if

display dialog "New Posix Path & File Name:" & return & PosixNewFile

tell application "Terminal"

do shell script "mv " & PosixOldFile & " " & PosixNewFile
-- generates success if there are no spaces in the path and/or filename.
-- generates error if there are the spaces in the path or filename.
end tell

end TermRename
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Help -- going posix space crazy
      • From: James Robinson <email@hidden>
    • Re: Help -- going posix space crazy
      • From: John Delacour <email@hidden>
  • Prev by Date: Remote access
  • Next by Date: Re: Addressing variables in subroutines
  • Previous by thread: Remote access
  • Next by thread: Re: Help -- going posix space crazy
  • Index(es):
    • Date
    • Thread