• 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 woes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: do shell script woes


  • Subject: Re: do shell script woes
  • From: Graff <email@hidden>
  • Date: Mon, 29 Dec 2003 23:06:21 -0500

On Dec 29, 2003, at 6:53 PM, Lorin Rivers wrote:

On Dec 24, 2003, at 9:21 PM, Lorin Rivers wrote:

This simple shell command works swimmingly from the command line in Panther, yet does nothing when called from my AppleScript.

set this_path to "/Users/lrivers/Desktop/cabs/06369022.cab"
--try
do shell script "/sw/bin/cabextract " & this_path

Suggestions?


BTW, .cab files are Windows archive files, typically OS related or in any case, coming from Microsoft. I wanted to write a little utility for extracting them because MS provides quite a few Office templates in that format. Alas...

Here's what I ended up doing. It was practically instantaneous. I'd still like to understand why it doesn't work from do shell script, but hey. The tech note practically says "don't expect do shell script to work".

On a whim I used Fink to grab cabextract and try this out myself. What I found out was very intresting. If you don't use the "-d" (destination directory) option for cabextract then it fails to extract any files even though it returns text stating that it has. This is probably due to the fact that cabextract would most likely extract those files to the working directory, which is kind of nebulous when called from AppleScript. This issue is explained in Technote 2065, but it's easy to miss due to the ton of information given in it:
<http://developer.apple.com/technotes/tn2002/tn2065.html>

The Q&A from that Technote:
---------
Q: What's the default working directory for do shell script commands?

A: do shell script inherits the working directory of its parent process. For most applications, such as Script Editor, this is /. For osascript, it's the working directory of the shell when you launched osascript. You should not rely on the default working directory being anything in particular. If you need the working directory to be someplace specific, set it to that yourself.
---------


If the working directory was one that you didn't have write permission on, such as "/", then any writes would fail and no files would get created. Cabextract probably should have returned an error but for some reason it doesn't.

This script works fine with cabextract:
---------
set srcPath to "~/Desktop/cabs/webhelp.cab"
set dstPath to "~/Desktop/cabs/extract/"
do shell script "/sw/bin/cabextract " & srcPath & " -d " & dstPath
---------


It's always a good idea before doing a shell script to either cd into a proper directory or to explicitly set the working directories using command flags such as "-d". If a command line tool doesn't have such a flag then run it like:
---------
set cdCMD to "cd ~/Desktop/cabs/extract/"
set cabCMD to "/sw/bin/cabextract ~/Desktop/cabs/webhelp.cab"
do shell script cdCMD & ";" & cabCMD
---------

This version also works fine with cabextract.

- Ken
_______________________________________________
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.

References: 
 >do shell script woes (From: Lorin Rivers <email@hidden>)
 >Re: do shell script woes (From: Lorin Rivers <email@hidden>)

  • Prev by Date: Re: mail.app save all attachments
  • Next by Date: Re: mail.app save all attachments
  • Previous by thread: Re: do shell script woes
  • Next by thread: Ideas for apps that allow digital sigs of PDFs?
  • Index(es):
    • Date
    • Thread