AppleScript error codes - Where can I get a complete list?

Hi,

I’ve been having some problems lately with my script that were not problems before…perhaps because of version upgrades and all.

I need to have access to a complete list of AppleScript codes and their meanings so I can have an idea what errors I need to look for in my codes.

Anybody knows where I can download such file? I tried to google this bulletin board but found no lead.

TIA.

archseed :frowning:

http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScript.109.html
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSScriptCommand.html#36822
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSScriptObjectSpecifier.html#BBCCCHDG

Hi,

I’ll be darned. I went to the developer’s website, made the search and still did not find it.

Your URL just took me directly where I wanted to go.

Thanks a lot. I’ve got what I need now.

archseed :slight_smile:

Hi archseed,

Note that Apple changed a lot of the numbers and added a few. For instance, there is no error number -1762 Apple event error listed. This is the same list in the AppleScriptLanguageGuide.

gl,

I doubt Apple have changed any error numbers as those are system-level codes and changing their meaning now would cause major breakage all over the place, not just in AS.

The error code list in the ASLG isn’t meant to be a comprehensive list of Mac OS error codes, only those that ASers are likely to encounter. Error -1762 (errOSACantOpenComponent) has been around forever, for example, but it’s not listed in the ASLG because you’re unlikely to encounter it in AS itself. Though if you do need a comprehensive list of classic Mac OS error codes, just Google for it.

Probably the main annoyance is that Cocoa doesn’t use classic Mac error codes itself, so most Cocoa-based apps return various NSError messages that AppleScript (which predates Cocoa) doesn’t know how to translate to more readable descriptions. The ASLG also predates Cocoa, hence the additional links to Cocoa Scripting error codes.

HTH

Hi hhas,

Thanks for the info!

I’m quite sure I came upon an error last week, looked up the error number and it changed, but maybe they just changed the message or something. If I get it again I’ll post it.

Thanks,

Hi,

Lots of thanks for the additional information.

Error -1762, I noted too, is not in the list that I looked at. I was zeroing in on that particular error code because it kept popping up in my little app; the entire list is useful for further info in case I do run into more troubles (hopefully, not).

Now, may I ask further how I can deal with this particular error code? I need some help in deciphering these Cocoa error messages. Does it mean that some component of my script cannot be opened? (just my little try at literal translation of the message).

Bad thing is my app (AS Studio) compiles successfully but fails on some aspects (the Quit part), making it difficult to debug. Wish I know a lot more how to use Xcode’s debug feature.

Thank you for your kind attention.

archseed :slight_smile:

Hi,

Here’s a quick update on the problem with the missing component that generated the Error Code -1762.

It is related to some windows in my AS Studio application that had “Released when closed” checked or activated. By unchecking them, it resolved my problem and does not generate any Error -1762 anymore.

Better still, the application is working well right now.

Thanks for the kind help.

archseed :slight_smile:

Is there a new location for the AppleScript documentation? All the above links are now 404 and AppleScript does not appear as a documentation “chapter”.

And a search for the string “AppleScript” in the provided search field does not produce anything…

https://www.cs.cmu.edu/afs/cs/user/lenzo/html/mac_errors.html

1 Like

Although it isn’t a list you can scroll through, there is also https://osstatus.com.

2 Likes

You can generate error code table by AppleScript.

--
--	Created by: Takaaki Naganoya
--	Created on: 2019/01/16
--
--	Copyright © 2019 Piyomaru Software, All Rights Reserved
--
use AppleScript version "2.7" -- Mojave (10.14) or later
use framework "Foundation"
use scripting additions

--AppleScript Errors
set erList to {-2700, -2701, -2702, -2703, -2704, -2705, -2706, -2707, -2708, -2709, -2720, -2721, -2729, -2740, -2741, -2750, -2751, -2752, -2753, -2754, -2755, -2760, -2761, -2762, -2763}

--macOS Errors
--{0, -34, -35, -37, -38, -39, -42, -43, -44, -45, -46, -47, -48, -49, -50, -51, -61, -108, -120, -124, -128, -192, -600, -601, -602, -605, -606, -607, -608, -609, -904, -905, -906, -915, -30720}

--AppleEvent Errors
--{-1700, -1701, -1702, -1703, -1704, -1705, -1706, -1707, -1708, -1709, -1710, -1711, -1712, -1713, -1714, -1715, -1716, -1717, -1718, -1719, -1720, -1721, -1723, -1725, -1726, -1727, -1728, -1729, -1730, -1731, -10000, -10001, -10002, -10003, -10004, -10005, -10006, -10007, -10008, -10009, -10010, -10011, -10012, -10013, -10014, -10015, -10016, -10023, -10024, -10025}

--OSA Errors
--{-1750, -1751, -1752, -1753, -1754, -1756, -1757, -1758, -1759, -1761, -1762, -1763}


set mesList to {}

repeat with i in erList
	set j to contents of i
	set {aNum, aMes} to errorGenerator(j) of me
	set the end of mesList to {aNum, aMes}
end repeat

mesList
--> {{-1743, "current applicationにApple Eventsを送信する権限がありません。"}}


on errorGenerator(aNum as number)
	set handlerName to "errorGenerator"
	try
		error number aNum
	on error errMsg number ErrNbr partial result partialResult from from_ to to_
		return {ErrNbr, errMsg}
	end try
end errorGenerator

2 Likes

The AppleScript Language Guide has an appendix that lists AppleScript and macOS error numbers and messages.

2 Likes

An interesting thing, at least to me, that I learned from this discussion is that “error number 0” is an error that does not error! Its error message is “no error.” and it terminates execution silently.

1 Like

Thank you all.

The error I was looking for is not on those lists.

I was trying something that was kind of bound to error (Emacs only provides a facility to open “mailto” locations):

osascript -e 'tell application "Emacs" to open location "file:///Users/suzume/Documents/OmegaT/application/readme_co.txt"'
28:107: execution error: Emacs got an error: An error of type -10653 has occurred. (-10653)

If you are working from the shell already, you don’t need to invoke applescript.

Try:

emacs 'Users/suzume/Documents/OmegaT/application/readme_co.txt'

If there are any options needed, put them between emacs and the file, for example:

emacs +5 'Users/suzume/Documents/OmegaT/application/readme_co.txt'

Or maybe use the shell’s open command:

open -a /Applications/Emacs.app 'Users/suzume/Documents/OmegaT/application/readme_co.txt'

As to the error, maybe that specific error can only appear if you have the GUI emacs installed. I get the following when I attempt with a local file:

28:74: execution error: Can’t get application "Emacs". (-1728)

I am testing AS access to Emacs.

osascript -e 'tell application "Emacs" to open location "mailto:my@email"'

works fine

And I know that Emacs does not provide an “open location” otherwise than “mailto”, but I was still wondering what that error was.

Here is a simpler script…

use AppleScript version "2.7" -- Mojave (10.14) or later
use scripting additions

set errList to {}

repeat with i from -1 to -30720 by -1
	local errMsg
	try
		error number i
	on error errMsg number errNum
		if (errMsg starts with "An error of type") and (errMsg ends with "has occurred.") then
			-- do nothing
		else
			set end of errList to (i as text) & ", " & errMsg
		end if
	end try
end repeat

get errList