• 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: Applescript-Shell Error Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Applescript-Shell Error Question


  • Subject: Re: Applescript-Shell Error Question
  • From: Jon Pugh <email@hidden>
  • Date: Sat, 15 Sep 2012 09:57:12 -0700

On Sep 15, 2012, at 8:16 AM, Christopher Stone wrote:
This script throws an error if there are items that have no quarantine bit set:

tell application "Finder"
set d to target of front window as string
end tell
set d to POSIX path of d
set cmd to "cd " & quoted form of d & ";xattr -d com.apple.quarantine *"
do shell script cmd

Is there a way to stop the error from propagating from the shell to Applescript?

I thought I could just do something like: 2>/dev/null

But it doesn't stop Applescript from throwing an error.

I know of course I can just put a try-block in the script, but I'm looking for a little deeper understanding.

The problem is that xattr is returning a non-zero result code, which “do shell script” turns into a thrown error.

The AppleScript way to cope is with a try/error block.

A Unix shell technique would be to end with a non-erroring command.  Just as an example, try this:

set cmd to "cd " & quoted form of d & ";xattr -d com.apple.quarantine *;echo Result: $?"

This will return a “Result: 1” instead of the text from xattr, which will break your script, but it will show the return value and prevent the “do shell script” from throwing.  There are a variety of more robust unix solutions, though a non-zero return code is traditionally very ignorable in Unix.

Since you want the info from xattr, this isn’t a proper solution, but it does illustrate what you are asking about.  ;)

In your case, catching the error would allow you to return a better string, like “Nothing has the quarantine bit set in this folder."

Jon

 _______________________________________________
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

  • Follow-Ups:
    • Re: Applescript-Shell Error Question
      • From: Christopher Stone <email@hidden>
References: 
 >Applescript-Shell Error Question (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: Applescript-Shell Error Question
  • Next by Date: Re: Applescript-Shell Error Question
  • Previous by thread: Re: Applescript-Shell Error Question
  • Next by thread: Re: Applescript-Shell Error Question
  • Index(es):
    • Date
    • Thread