# Auth: Christopher Stone
# dCre: 2013-05-20 : 16:36
# dMod: 2013-05-20 : 17:08
# Appl: Script Debugger
# Task: Save Script Aliases & Unsaved Script Source to Saved-Session-Scripts folder.
# Libs: err.lib, find.lib, gen.lib (Irrelevant in posted script.)
# Osax: Satimage.osax
# Tags: @Applescript, @Script_Debugger, @Backup, @Dump, @Session
-------------------------------------------------------------------------------------------
try
set unsavedFlag to false
tell application "Script Debugger"
set sdAppSuptFldr to (join (items 1 thru -3 of (splittext (templates folder as text) using ":")) using ":") & ":"
set dumpFldr to sdAppSuptFldr & "Saved-Session-Scripts:"
set scriptPathList to file spec of documents whose path contains "users/"
set unsavedDocSrcL to source text of every document whose name starts with "Untitled"
if unsavedDocSrcL ≠ {} then
repeat with i in unsavedDocSrcL
# Strip whitespace off top and bottom of src:
end repeat
set unsavedFlag to true
end if
end tell
set _date to strftime (get current date) into "%Y.%m.%d.%H%M%S"
set newFldrPathH to (dumpFldr & "Session_Dump_" & _date) & ":"
do shell script "mkdir -p " & (quoted form of (POSIX path of newFldrPathH))
set writeToAlias to alias newFldrPathH
tell application "Finder"
repeat with i in scriptPathList
make new alias file at writeToAlias to (i)
end repeat
open alias dumpFldr
end tell
if unsavedFlag then
repeat with i from 1 to length of unsavedDocSrcL
writetext (item i of unsavedDocSrcL) to file ((newFldrPathH as text) & "Unsaved_Script_Src_" & i & ".applescript")
end repeat
end if
on error e number n
stdErr(e, n, true, true) of me
end try
-------------------------------------------------------------------------------------------
on cng(findText, changeText, srcData)
change findText into changeText in srcData with regexp without case sensitive
end cng
-------------------------------------------------------------------------------------------
on stdErr(e, n, beepFlg, ddFlg)
set e to e & return & return & "Num: " & n
if beepFlg = true then
beep
end if
if ddFlg = true then
tell me
set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
end tell
if button returned of dDlg = "Copy" then set the clipboard to e
else
return e
end if
end stdErr
-------------------------------------------------------------------------------------------