Hi Again Yvan,
Thanks for taking the time to help out.
I copied the script into Script Editor, but when I run it I got errors. I changed to what I thought the code should be (copied below) and it now runs ok, but none of the following return the document. From the Log:
tell application "Microsoft Word" activate get every document whose full name = "JaundicedOutlook:Users:Excession:Desktop:TestDocs:Word-Test1.docx" (*missing value*)
get every document whose full name = "JaundicedOutlook:Users:Excession:Desktop:TestDocs:Word-Test1.docx" (*missing value*)
get every document whose full name = "JaundicedOutlook:Users:Excession:Desktop:TestDocs:Word-Test1.docx" (*missing value*)
get every document whose full name = "/Users/Excession/Desktop/TestDocs/Word-Test1.docx" (*missing value*) end tell
I’m not sure if my changes are correct or not?
All the Best Dave
———————————————————————————————————————————————————
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 myDocumentIDfromPosix to path of disk item myPosixPath —****************************CHANGED log myDocumentIDfromPosix (*SSD 500:Users:yvankoenig:Desktop:Sans titre.docx*) end tell
# Scheme 2bis (alternate) set myDocumentIDAltFromPosix to myPosixPath as text --*********************************** CHANGED 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" activate --*********************************** CHANGED 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
May you open a word document and post what is returned by this short script ?
tell application id "com.microsoft.Word" activate full name of document 1 end tell
In the dictionary to which I have access, I found two descriptions of full name. For a document it's described as : full name (text, r/o) : Returns the full name of the document. For a template it's described as :full name (text, r/o) : Specifies the name of the template including the drive or Web path.
The difference let me think that for a document, full name doesn't mean the full pathname but the file name with its extension. It seems logical as a document has also a property named "path"
So, the problem becomes : what are you really wanted to get, the open documents owning a given name or possibly those with a given path ? If you want to get open documents with a given name you don't have to grab the pathname as text but only the file name
Here is a short script showing how to get the name of a file with different classes or original descriptor.
set myDocument to choose file of type {"Doc", "Docx"} class of result
tell application "System Events" set name0 to name of myDocument end tell
tell application "System Events" set name1 to name of disk item (myDocument as text) end tell
set myDocumentPosix to POSIX path of myDocument
# Extract the name of a posix path tell application "System Events" set name2 to name of disk item myDocumentPosix end tell
log "name1 is : " & name1 & return & "name2 is : " & name2
set myDocumentPosixFile to POSIX file myDocumentPosix log (get class of myDocumentPosixFile) --> (*«class furl»*) tell application "System Events" set name3 to name of disk item (myDocumentPosixFile as text) end tell
log "name0 is : " & name0 & return & "name1 is : " & name1 & return & "name2 is : " & name2 & return & "name3 is : " & name3
As you will see, there is a short syntax when the original is an alias object. But we may get the correct result with the same syntax for alias, posix path and «class furl» so I guess that it's the one to use.
tell application "System Events" # Here myDocument may be an alias object, a POSIX path or a «class furl» object set name to name of disk item (myDocument as text) end tell
Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) jeudi 16 juin 2016 12:12:43
|