Hi All,
Given the following Handlers:
on getPOSIXPathWithMacPath:(theMacPath) set myFullNamePOSIX to the POSIX path of theMacPath return myFullNamePOSIX end getPOSIXPathWithMacPath:
on getMacPathWithPOSIXPath:(thePOSIXPath as text) set myMacPath to thePOSIXPath as POSIX file return myMacPath end getMacPathWithPOSIXPath:
on getActiveDocumentID() tell application id "com.microsoft.Word" set myDocument to the active document set myDocumentFullName to the full name of myDocument if myDocumentFullName does not contain ":" then return myDocumentFullName set myDocumentID to my getPOSIXPathWithMacPath:(myDocumentFullName) end tell return myDocumentID as text end getActiveDocumentID
on getWordDocumentWithDocumentID:(theDocumentID as text) if theDocumentID = missing value then return missing value
if theDocumentID does not contain "/" then tell application id "com.microsoft.Word" set myDocumentList to (every document whose name is theDocumentID) if the count of myDocumentList = 0 then return missing value end if
set myDocument to item 1 of myDocumentList return myDocument end tell end if set myDocumentID to my getMacPathWithPOSIXPath:(theDocumentID) if myDocumentID = missing value then return missing value tell application id "com.microsoft.Word" set myDocumentList to (every document whose full name is myDocumentID) if the count of myDocumentList = 0 then return missing value end if
set myDocument to item 1 of myDocumentList end tell
return myDocument end getWordDocumentWithDocumentID:
The above seems to work ok with MS Office 2011, but I’m getting reports of problems in 2016. Can anyone see why the might cause a problem?
This is in an XCode project and is being called from Objective-C using AS-ObjC.
Thanks in advance.
All the Best Dave
I respond in the dark because I received your message on my HD testing Sierra and I am back to the one running El Capitan on which the message is not available.
Run this simple script from the Apple's Script Editor.
set myDocument to choose file of type {"Doc", "Docx"}
# Initial value is a «class furl» object. Two esay schemes are available # Scheme 1 tell application "System Events" set myDocumentID to path of myDocument log myDocumentID (*SSD 500:Users:yvankoenig:Desktop:Sans titre.docx*) end tell # Scheme 2 (alternate) set myDocumentIDAlt to myDocument as text log myDocumentIDAlt (*SSD 500:Users:yvankoenig:Desktop:Sans titre.docx*) log myDocumentID & return & myDocumentIDAlt (*SSD 500:Users:yvankoenig:Desktop:Sans titre.docx SSD 500:Users:yvankoenig:Desktop:Sans titre.docx*)
set myPosixPath to POSIX path of myDocument # If the initial value is a POSIX path (we just buitlt one. # Scheme 1bis tell application "System Events" set myDocumentID to path of disk item myPosixPath log myDocumentIDfromPosix (*SSD 500:Users:yvankoenig:Desktop:Sans titre.docx*) end tell # Scheme 2bis (alternate) set myDocumentIDAlt to myPosixPath as text log myDocumentIDAltFromPosix (*/Users/yvankoenig/Desktop/Sans titre.docx*) log myDocumentID & return & myDocumentIDAlt (*SSD 500:Users:yvankoenig:Desktop:Sans titre.docx /Users/yvankoenig/Desktop/Sans titre.docx*) # I don't know if the second result is OK for Word
tell application id "com.microsoft.Word" set myDocumentList1 to (every document whose full name is myDocumentID) log myDocumentList1 set myDocumentList2 to (every document whose full name is myDocumentIDAlt) log myDocumentList2 set myDocumentList3 to (every document whose full name is myDocumentIDfromPosix) log myDocumentList3 set myDocumentList4 to (every document whose full name is myDocumentIDAltFromPosix) log myDocumentList4 end tell
It will show you which is the correct syntax to use.
Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) mercredi 15 juin 2016 23:34:25
|