Speeding Up an AppleScript especially running under AppleScript-ObjC Bridge
Speeding Up an AppleScript especially running under AppleScript-ObjC Bridge
- Subject: Speeding Up an AppleScript especially running under AppleScript-ObjC Bridge
- From: Dave <email@hidden>
- Date: Tue, 15 Mar 2016 12:06:22 +0000
Hi,
The getWordStandardDocumentDictionaryWithDocumentID and setWordStandardDocumentPropertiesDictionary taking way too long to run which isn’t surprising given the amount of indirection in terns of calling low level handlers.
I’m going to rewrite it to access the properties inline rather than calling low level methods but I’d really appreciate any tips on getting the best performance when using the AppleScript-ObjC Bridge.
Thanks a lot,
All the Best
Dave
on getWordStandardDocumentPropertyWithDocumentID:(theDocumentID as string) andPropertyName:(thePropertyName as string)
--say "getWordStandardDocumentPropertyWithDocumentID: " & theDocumentID
set myDocument to my getWordDocumentWithDocumentID:(theDocumentID)
tell application id "com.microsoft.Word"
set myValue to the value of (document properties of myDocument whose name is thePropertyName)
end tell
return myValue
end getWordStandardDocumentPropertyWithDocumentID:andPropertyName:
on setWordStandardDocumentPropertyWithDocumentID:(theDocumentID as string) andPropertyName:(thePropertyName as string) andPropertyValue:(thePropertyValue as string)
--say "setWordStandardDocumentPropertyWithDocumentID:"
set myDocument to my getWordDocumentWithDocumentID:theDocumentID
tell application id "com.microsoft.Word"
set the value of (document properties of myDocument whose name is thePropertyName) to thePropertyValue
end tell
end setWordStandardDocumentPropertyWithDocumentID:andPropertyName:andPropertyValue:
on getWordStandardDocumentDictionaryWithDocumentID:(theDocumentID as string)
--say "getWordStandardDocumentDictionaryWithDocumentID:" --& theDocumentID
set myStandardDocumentPropertiesDictionary to my newWordStandardDocumentDictionary()
tell application id "com.microsoft.Word"
--
-- Set Up the Message Properties Dictionary
--
set kDocumentID of myStandardDocumentPropertiesDictionary to theDocumentID
set kDocumentTitle of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Title"
set kDocumentSubject of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Subject"
set kDocumentAuthor of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Author"
set kDocumentKeywords of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Keywords"
set kDocumentComments of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Comments"
set kDocumentTemplate of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Template"
set kDocumentLastAuthor of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Last author"
set kDocumentRevisionNumber of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Revision number"
set kDocumentApplicationName of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Application name"
set kDocumentLastPrintDate of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Last print date"
set kDocumentCreationDate of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Creation date"
set kDocumentLastSaveTime of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Last save time"
set kDocumentTotalEditingTime of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Total editing time"
set kDocumentNumberOfPages of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Number of pages"
set kDocumentNumberOfWords of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Number of words"
set kDocumentNumberOfCharacters of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Number of characters"
set kDocumentSecurity of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Security"
set kDocumentCategory of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Category"
set kDocumentFormat of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Format"
set kDocumentManager of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Manager"
set kDocumentCompany of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Company"
set kDocumentNumberOfBytes of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Number of bytes"
set kDocumentNumberOfLines of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Number of lines"
set kDocumentNumberOfParagraphs of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Number of paragraphs"
set kDocumentNumberOfSlides of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Number of slides"
set kDocumentNumberOfNotes of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Number of motes"
set kDocumentNumberOfHiddenSlides of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Number of hidden slides"
set kDocumentNumberOfMultiMediaClips of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Number of multimedia clips"
set kDocumentHyperlinkBase of myStandardDocumentPropertiesDictionary to my getWordStandardDocumentPropertyWithDocumentID:theDocumentID andPropertyName:"Hyperlink base"
end tell
return myStandardDocumentPropertiesDictionary as record
end getWordStandardDocumentDictionaryWithDocumentID:
------------------------------------------------------------------------------------------
--
-- setWordStandardDocumentDictionary:
--
------------------------------------------------------------------------------------------
on setWordStandardDocumentPropertiesDictionary:(theStandardDocumentDictionary as record)
--say "setWordStandardDocumentDictionary:"
copy theStandardDocumentDictionary to myStandardDocumentPropertiesDictionary
set myDocumentID to kDocumentID of myStandardDocumentPropertiesDictionary
set myDocument to my getWordDocumentWithDocumentID:(myDocumentID)
tell application id "com.microsoft.Word"
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Title" andPropertyValue:(kDocumentTitle of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Subject" andPropertyValue:(kDocumentSubject of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Author" andPropertyValue:(kDocumentAuthor of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Keywords" andPropertyValue:(kDocumentKeywords of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Comments" andPropertyValue:(kDocumentComments of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Template" andPropertyValue:(kDocumentTemplate of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Last author" andPropertyValue:(kDocumentLastAuthor of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Revision number" andPropertyValue:(kDocumentRevisionNumber of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Application name" andPropertyValue:(kDocumentApplicationName of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Last print date" andPropertyValue:(kDocumentLastPrintDate of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Creation date" andPropertyValue:(kDocumentCreationDate of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Last save time" andPropertyValue:(kDocumentLastSaveTime of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Total editing time" andPropertyValue:(kDocumentTotalEditingTime of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Number of pages" andPropertyValue:(kDocumentNumberOfPages of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Number of words" andPropertyValue:(kDocumentNumberOfWords of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Number of characters" andPropertyValue:(kDocumentNumberOfCharacters of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Security" andPropertyValue:(kDocumentSecurity of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Category" andPropertyValue:(kDocumentCategory of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Format" andPropertyValue:(kDocumentFormat of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Manager" andPropertyValue:(kDocumentManager of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Company" andPropertyValue:(kDocumentCompany of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Number of bytes" andPropertyValue:(kDocumentNumberOfBytes of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Number of lines" andPropertyValue:(kDocumentNumberOfLines of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Number of paragraphs" andPropertyValue:(kDocumentNumberOfParagraphs of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Number of slides" andPropertyValue:(kDocumentNumberOfSlides of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Number of motes" andPropertyValue:(kDocumentNumberOfNotes of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Number of hidden slides" andPropertyValue:(kDocumentNumberOfHiddenSlides of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Number of multimedia clips" andPropertyValue:(kDocumentNumberOfMultiMediaClips of myStandardDocumentPropertiesDictionary)
get my setWordStandardDocumentPropertyWithDocumentID:myDocumentID andPropertyName:"Hyperlink base" andPropertyValue:(kDocumentHyperlinkBase of myStandardDocumentPropertiesDictionary)
end tell
end setWordStandardDocumentPropertiesDictionary:
_______________________________________________
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