Hello,
Firstly I’m new to Applescript so I’m sorry if I ask anything to obvious.
Some background about me:
I’m used to programming in Object Orientated languages like C Sharp, and Java, but no Dot notation seems to exist for Applescript.
I’m trying to write a script for use with Quark, this script will interrogate a Quark document and write values into an XML file.
The problem I’ve got is getting hold of the document object.
If a person has more than one file open then they need to specify which file we should work with. I’ve written code that finds the names of the open files, and displays a list. The user then selects a file from this list and presses OK. Using this text value I again loop through the document. When I find a match I then set a property. Then I call a function. It is at this function things start to go awry. At the moment the error message I get is: Can’t make name of document into type string
i think there are two questions: Am I getting hold of the document correctly, and is this possible?
set docCount to document count -- find how many documents are open
set docList to {} -- this list will hold the names of the open documents
if (docCount is greater than 1) then
--Initialise our array/list
repeat docCount times
set end of docList to ""
end repeat
display dialog "You have " & docCount & " files open. Which one should we work with?"
repeat with i from 1 to docCount -- This repeat adds the names of the documents to our list
tell document i
set DocName to name as text
set item i of docList to DocName
end tell
end repeat
-- These two lines find which document name has been selected
set chosenFile to (choose from list docList with prompt "Which item?" cancel button name "Cancel" without multiple selections allowed)
set chosenFile to chosenFile as text
--- this loop matches the chosen File name with our open documents
repeat with i from 1 to docCount
tell document i
set DocName to name as text
display dialog ("This is the file we've found " & DocName)
if chosenFile = DocName then
display dialog "The names match"
set theDoc to document -- set this variable to be the document. Is this assumption correct?
exit repeat
end if
end tell
end repeat
processChosenFile(theDoc)
else if (docCount is 1) then
display dialog "You have a file open"
processChosenFile(document 1)
else
display dialog "you have no files open"
end if
on processChosenFile(docQuark)
display dialog "At least we reach the function"
tell docQuark
set DocName to name as text
--set DocName to name of docQuark as string
display dialog (DocName)
end tell
end processChosenFile