Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*
- It is easier to diagnose problems with debug information. This applescript demonstaties how to create a log file.
- Author: rccharles
- Write debug text to the file debugLog.txt in your home folder ( ~/debugLog.txt ).
- example of the file ~/debugLog.txt:
- New log created on Wednesday, May 15, 2013 2:12:41 PM
- --- debug on Wednesday, May 15, 2013 2:12:41 PM ---
- --- current AppleScript is Ext-Remainder:Applications:applescriptFiles:demo:log user data.app: ---
- start program.
- thePath = Ext-Remainder:
- End of program.
- --- debug on Wednesday, May 15, 2013 2:15:14 PM ---
- --- current AppleScript is Ext-Remainder:Applications:applescriptFiles:demo:log user data.app: ---
- start program.
- thePath = Ext-Remainder:
- End of program.
- fyi:
- The applescript log statements are ignored when not running from the script editor.
- Not to be confused, this applescript contains log statements that have nothing to do with creating a log file.
- They are to help the script author write the script.
- *)
- on run
- -- thePath points to the folder in which to create the debug log.
- global thePath, firstRunning
- (* Use the path to clause to create a generalized path statements *)
- set thePath to (path to home folder as string)
- set firstRunning to ""
- -- Write a message into the applescript editor event log.
- log " --- Starting on " & ((current date) as string) & " --- "
- debug("start program. ")
- (*
- Your program here...
- *)
- debug("thePath = " & thePath)
- debug("End of program. ")
- end run
- -- ----------------------------------------------------------
- on appendToFile(fileId, theData)
- local theSize, writeWhere
- set theSize to (get eof fileId)
- set writeWhere to theSize + 1 as integer
- write theData to fileId starting at writeWhere
- end appendToFile
- -- ----------------------------------------------------------
- -- based on log by James Reynolds, 12.18.2000, University of Utah
- on debug(theMessage)
- global thePath, firstRunning
- local theSize, startupDiskName, pathToLog, fileReference, appPath
- set pathToLog to (thePath & "debugLog.txt")
- try
- set fileReference to (open for access file pathToLog ¬
- with write permission)
- log "firstRunning = " & firstRunning
- set theSize to (get eof fileReference)
- if firstRunning = "" then
- set theSize to (get eof fileReference)
- log "theSize = " & theSize
- if theSize is equal to 0 then
- appendToFile(fileReference, "New log created on " & ((current date) as string) & " " & return)
- tell application "Finder"
- set the creator type of the file pathToLog ¬
- to "R*ch"
- end tell
- end if
- appendToFile(fileReference, " --- debug on " & ((current date) as string) & " --- " & return)
- tell current application
- set appPath to path to current application
- end tell
- appendToFile(fileReference, " --- current AppleScript is " & appPath & " ---" & return)
- set firstRunning to "running"
- end if
- appendToFile(fileReference, theMessage & return)
- close access fileReference
- on error mes
- try
- log " We got an error when writing to " & mes
- close access fileReference
- end try
- end try
- end debug
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement