• 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: Do Shell script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Do Shell script


  • Subject: Re: Do Shell script
  • From: Christopher Nebel <email@hidden>
  • Date: Mon, 24 Oct 2005 09:13:22 -0700


On Oct 23, 2005, at 5:39 AM, John Mitchell wrote:

I have over 9000 file date errors in the log after a duplicate using Retrospect.

I thought I could write a script that read the log, found the path of the file and then UNIX touched it.

--parse the log into a list of UNIX file paths
set {flag, dsList} to processFile(theFile)

--
now update DOM to be after DOC, ie today
set current_user to (do shell script "id -un")
set store_target to ("/Users/" & current_user & "/")
repeat with thisItem in dsList
   
try
            
set UNIXpath to store_target & thisItem
       
do shell script "touch -acfm " & UNIXpath
      
on error errMsg number errNum
          
display dialog errMsg & space & (errNum as string)
     
end try
end repeat

however although I get no error (" ") the date is not updated. I tried adding "with administrator privileges" but no result.

The most likely explanation is that UNIXpath is pointing to a file that doesn't exist -- touch won't report errors for that sort of thing.  (It will either create the file, or, if you used the -c flag as you did, do nothing.)  There are two obvious possible errors:

1. If the file path has any spaces or special characters, you'll need to quote it.  Use "quoted form of UNIXpath" instead.

2. The way your routine is written assumes that processFile returns a list of POSIX paths, all relative to your home directory.  At the moment, I'm obliged to take it on faith that it does this reliably; there may be a problem there.

Try looking at the event log, and see what the final "do shell script" command turns out to be.  While you're at it, go read <http://developer.apple.com/technotes/tn2002/tn2065.html>, essential reading if you plan to use "do shell script" with any frequency.

There are also a couple of more subtle problems:

1. "touch -am", if I'm reading the man page right, is the same thing as "touch".  By default, it updates both access and modification times.

2. If you want the current user's home directory, a faster and more correct way to do it is to use the shell variable "$HOME" -- for example 'set store_target to do shell script "echo $HOME"'.  Your solution won't work for users that have their home folder somewhere other than the startup disk (like me).  If you prefer a more AppleScript-centric solution, say "set store_target to POSIX path of (path to home folder)".



--Chris Nebel
AppleScript and Automator Engineering

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Do Shell script (From: John Mitchell <email@hidden>)

  • Prev by Date: Warning: tcsh, osascript, and HERE docs
  • Next by Date: Re: Do Shell Script
  • Previous by thread: Re: Do Shell script
  • Next by thread: Do Shell Script
  • Index(es):
    • Date
    • Thread