0

I am trying to throw a specific error code inside of a applescript snippet that I am running via osascript.

This is my code:

osascript -e "if ((clipboard info) as string) does not contain \"«class PNGf»\" then" -e "error number 61" -e "end if"

However, I either get statuscode 1 or 0 instead of getting either 0 or 61. Is there any way to forward the errors?

Marcel
  • 1,509
  • 1
  • 17
  • 39
  • Running **osascript** by itself returns an execution error with the provided message and number - how are you getting the result? – red_menace Feb 13 '19 at 15:07
  • Well, I tried getting the actual exit code returned by the osascript process. You mean there is no other way but parsing the output? – Marcel Feb 13 '19 at 15:18
  • Performing `osascript -e 'error "this is an error" number 128'` results in something like `6:24: execution error: this is an error (128)` - you can print the script errors to stdout or stderr, but that is the output from the script. – red_menace Feb 13 '19 at 15:36
  • I see, I thought I might be able to make it send a exit status code instead. because parsing a string doesn't quite feel like the it should be. – Marcel Feb 13 '19 at 20:11

1 Answers1

0

The exit status of osascript is like any other command, but you will need to look at its output to see the specific result of the script (which is where the error number you are interested in is coming from).

osascript normally prints script errors to stderr, but another method is to use the -s o option to also print script errors to stdout, and check the exit status to determine if you need to process the output from the script as an error (or not).

red_menace
  • 3,162
  • 2
  • 10
  • 18