Applescript Error Handling
Contents |
numbers and error messages provided by AppleScript and macOS.AppleScript ErrorsAn AppleScript error is an error that occurs when AppleScript processes script statements. Nearly all of these are of interest to
Applescript Try Error
users. For errors returned by an application, see the documentation for that applescript error catching application.Table B-1AppleScript errorsError numberError message-2700Unknown error.-2701Can’t divide
Applescript Tutorial
be launched because it is not an application.-2704
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this
Applescript Error Codes
site About Us Learn more about Stack Overflow the company Business Learn more applescript error user canceled about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x
Applescript Error 10810
Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up AppleScript: on https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_error_codes.html error (try) line number up vote 11 down vote favorite 2 Is it possible to get the line number, where the script threw an error? Example: try set a to "abc" + "123" on error line number num display dialog "Error on line number " & num end try applescript try-catch onerror share|improve this question asked May 12 '11 at 12:46 Tyilo 11.2k1863139 add http://stackoverflow.com/questions/5978199/applescript-on-error-try-line-number a comment| 4 Answers 4 active oldest votes up vote 18 down vote accepted i don't think so try statements look like this try set a to "abc" + "123" on error errMsg display dialog "ERROR: " & errMsg end try but you could look at script debugger which will show you what line your error occurred on another alternative is to get textmate which goes for $52 when it errors it gives you the line number and is also useful for writing code in many languages share|improve this answer edited Apr 10 '13 at 15:07 answered May 12 '11 at 15:39 mcgrailm 11.2k1554109 2 $199 for an apple script debugger, no thanks. +1 for pointing it out, though. –Adam Eberlin Apr 10 '13 at 0:49 @AdamEberlin see my new edit –mcgrailm Apr 10 '13 at 15:07 why the down vote or removal of vote not sure which , but noticed i went down 10 points –mcgrailm Jun 15 '13 at 16:11 wasn't me.. o.O –Adam Eberlin Jul 10 '13 at 22:02 add a comment| Did you find this question interesting? Try our new
tricks and tips Posts RSS Comments RSS 48 Posts and 150 Comments till now Trapping error codes in AppleScript If you use AppleScript you know sometimes when you try to do things such as mount a remote volume things can go wrong. http://macstuff.beachdogs.org/blog/?p=28 Then you get a error message with number telling (hopefully) what went wrong. But you might not want that error message to show up. Maybe if that error happens you want your script to do something. If so then https://www.safaribooksonline.com/library/view/applescript-in-a/1565928415/re116.html you have to trap that error first. To catch an error you need to wrap the part of your script that is doing the action in a try statement. So, if I wanted to open a file I script error might use something like this: Code blocktry tell application "Finder" open file "Hard Drive:Users:joe:oops.txt" end tell on error errmsg end try The script trys to run that command and if there is a problem the error message gets put into the variable errmsg. Then we can handle that error another way, perhaps with a dialog box. Code blocktry tell application "Finder" open file "Hard Drive:Users:joe:oops.txt" end tell on error errmsg display dialog errmsg buttons {"Oops"} end script error handling try That works great for generic errors but what if we know the error code of a specific error, such as the file doesn't exist ,which happens to be -1728. Then we can add the number property to our on error trap and do something specific for that error. Code blocktry tell application "Finder" open file "Hard Drive:Users:joe:oops.txt" end tell on error errmsg number errNum if errNum is -1728 then display dialog "Hey, that file doesn't exist!" buttons {"Doh!"} else display dialog errmsg buttons {"Oops"} end try Now we can give the user specific feedback on certain errors and just display the error message for all other errors. Be Sociable, Share! Tweet admin :: May.10.2007 :: Applescript, Scripts :: No Comments » Comments are closed. Trackback this post | Categories Applescript Automator Management Scripts Server shell scripts System Terminal Training Uncategorized Widgets Please help support this site: Pages About this site Contact Me Mavericks 10.9 Apple Certification and Training Books Mountain Lion 10.8 Apple Certification and Training books Recommended AppleScript Books for Beginners Admin sites AFP548 MacEnterprise.org Blogroll Infinite Loop Mind the explanatory gap The Joy of Tech Help sites Macfixit macosxhints.com MacResearch News Mac Rumors MacWorld The Unofficial Apple Weblog Meta Log in Entries RSS Comments RSS WordPress.org Mac Stuff Copyright © 2016 All Rights Reserved WordPress Theme sponsored by Web Hosting Unleashed's Unlimited Domain Hosting Guide.
a Nutshell by Bruce W. Perry Published by O'Reilly Media, Inc. Special Upgrade Offer A Note Regarding Supplemental Files Preface Organization of This Book Part I Part II Part III Part IV Part V Part VI Conventions Used in This Book How to Contact Us Acknowledgments I. Introduction to AppleScript 1. AppleScript: An Introduction How Is AppleScript Used? Apple Events Using Script Runner with OS X Using OSA Menu with OS 9 Checking Your AppleScript Version Diving In 2. Using Script Editor with OS 9 and OS X Script Editor Controls/Commands Scripting the Script Editor II. AppleScript Language Reference 3. Data Types alias boolean class constant data date file specification integer international text list number real record reference RGB color string Styled Clipboard Text Styled Text text Unicode Text Unit of Measurement Classes 4. Operators & ( ) * + - / ÷ div < ≤ <= = > ≥ >= ^ [a] reference to and as begin[s] with contains does not contain does not equal ends with is contained by is not contained by mod not or 5. Reference Forms after back before beginning first, second, third, fourth, etc. every every ... from ... to ... id last middle name some whose 6. Variables and Constants Variables Constants and Predefined Variables 7. Flow-Control Statements considering [but ignoring] end [considering] continue error exit [repeat] if simple statement if [then] [else if] [else] end [if] ignoring [but considering] end [ignoring] repeat end [repeat] repeat until end [repeat] repeat while end [repeat] repeat with {loop variable} from {integer} to {integer}[by stepVal] end [repeat] repeat with {loop variable} in {list} end [repeat] repeat {integer} times end [repeat] return [return value] tell simple statement tell end [tell] try [on error] [number | from | partial result | to] end[error | try] using terms from end [using terms from] with timeout [of] {integer} second[s] end [timeout] with transaction [session object] end [transaction] 8. Subroutines Subroutines with Positional Parameters Subroutines with Labeled Parameters 9. Script Objects and Libraries Script Objects Libraries III. Scripting Mac OS 9 Applications 10. Apple Guide and Help Viewer Apple Guide Help Viewer 11. Apple System Profiler Apple System Profiler 12. Keychain Scripting