Re: Extracting Script Library Text and/or Handler Calls
Re: Extracting Script Library Text and/or Handler Calls
- Subject: Re: Extracting Script Library Text and/or Handler Calls
- From: Christopher Stone <email@hidden>
- Date: Tue, 24 Apr 2018 00:00:57 -0500
On 04/23/2018, at 23:02, Christopher Stone <email@hidden
<mailto:email@hidden>> wrote:
> On my own system where all the script libraries are created as script bundles
> with Script Debugger I use AppleScriptObjC to decode SD's backup RTF file
> embedded in each library.
>
> Why? Because it's very, very fast. :)
>
> I'll post this script separately soon.
Hey Folks,
Remember – this script REQUIRES the library scripts at ~/Library/Scripts/ to
have been created with Script Debugger – and they MUST be script bundles
(.scptd) NOT plain compiled scripts (.scpt).
That's because I'm trying to eek out every millisecond of speed I can and am
therefore converting Script Debugger's backup RTF file to text instead of using
osadecompile.
This shell scripts I posted run in approximately 0.85 seconds on my system to
convert 6 rather large libraries.
By contrast this script runs in approximately 0.12 seconds, and that's fast
enough to use it live for a variety of things.
If you don't use Script Debugger <http://www.latenightsw.com/> then the other
scripts are what you need, but there're still some useful AppleScriptObjC
goodies in this one you can cannibalize.
--
Best Regards,
Chris
----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2018/04/23 23:39
# dMod: 2018/04/23 23:39
# Appl: AppleScriptObjC
# Task: Extract text from script libraries and process to return handler-calls.
# Reqs: Script MUST be a script BUNDLE created with SCRIPT DEBUGGER.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Extract, @Text, @Libraries, @Process,
@Handler-Calls
----------------------------------------------------------------
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
set AppleScript's text item delimiters to linefeed
set scptLibFldr to POSIX path of ((path to library folder from user domain as
text) & "Script Libraries:")
set rtfPath to "/Contents/Resources/Scripts/main.recover.rtf"
set fileList to (its findFilesWithRegEx:".*Lb.*" inDir:scptLibFldr) as text
set fileList to text items of (its regxRepl:"(?m)$" inString:fileList
usingPattern:rtfPath)
set collatedText to {}
repeat with theFile in fileList
set end of collatedText to (its rtf2Text:theFile)
end repeat
set collatedText to collatedText as text
set collatedText to its regxRepl:"(?m)^(?>(?:(?!^on ).)+)[\\n\\r]*"
inString:collatedText usingPattern:""
set collatedText to its regxRepl:"(?m)^on " inString:collatedText
usingPattern:""
# Break text into a list if desired.
# set collatedText to paragraphs of collatedText
set AppleScript's text item delimiters to {""}
return collatedText
----------------------------------------------------------------
--» HANDLERS
----------------------------------------------------------------
on findFilesWithRegEx:findPattern inDir:srcDirPath
set fileManager to current application's NSFileManager's defaultManager()
set sourceURL to current application's |NSURL|'s fileURLWithPath:srcDirPath
set theURLs to fileManager's contentsOfDirectoryAtURL:sourceURL
includingPropertiesForKeys:{} options:(current application's
NSDirectoryEnumerationSkipsHiddenFiles) |error|:(missing value)
set theURLs to theURLs's allObjects()
set foundItemList to current application's NSPredicate's
predicateWithFormat_("lastPathComponent matches %@", findPattern)
set foundItemList to theURLs's filteredArrayUsingPredicate:foundItemList
set foundItemList to (foundItemList's valueForKey:"path") as list
end findFilesWithRegEx:inDir:
----------------------------------------------------------------
on regxRepl:_find inString:_data usingPattern:_replace
set theRegEx to current application's NSRegularExpression's
regularExpressionWithPattern:_find options:0 |error|:(missing value)
set theResult to theRegEx's stringByReplacingMatchesInString:_data
options:0 range:{location:0, |length|:length of _data} withTemplate:_replace
return theResult as text
end regxRepl:inString:usingPattern:
----------------------------------------------------------------
on rtf2Text:thePath
set attString to current application's NSAttributedString's alloc()'s
initWithPath:thePath documentAttributes:(missing value)
return (attString's |string|()) as text
end rtf2Text:
----------------------------------------------------------------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden