(2)"is running" is not part of Numbers scripting dictionary.
(3) "active document" is not part of Numbers scripting dictionary.
(4) " does not contain "Document" " is perhaps meaningful when running Excel but with Numbers such a test is a no-no.
When Numbers is ran in French, a document which was never saved is named "Sans titre" or "Sans titre 2" or higher number.
I guess that in English it would be "Untitled" or "Untitled 2" or higher number.
When a document was saved at least once, its name is something like "oneMoreThing.numbers" — at least if like me you urge the application to always give document the name extension.
In fact, as I am accustomed to work this way I’m not sure that we way work without the name extension with v3.2.2.
The cleaner way to know if a Numbers document was saved is to use this kind of code :
tell application "Numbers"
file of every document
--> {file "<myHD>:Users:<myAccount>:Desktop:truc.numbers", missing value, missing value}
end tell
When I ran this sample, the front document was already saved, the two others weren’t.
So, I assume that something like :
tell application "Numbers"
repeat
set theFiles to file of every document
--> {file "<myHD>:Users:<myAccount>:Desktop:truc.numbers", missing value, missing value}
if theFiles does not contain missing value then exit repeat
repeat with i from 1 to count theFiles
if item i of theFiles is missing value then
save document i in file (my createAfile())
delay 1 # to be sure to use a different name
exit repeat
end if
end repeat
end repeat
end tell
#=====
on createAfile()
set p2d to path to desktop as text
set newName to my horodateur(current date) & ".numbers"
tell application "System Events"
make new file at end of folder p2d with properties {name:newName}
end tell
return p2d & newName
end createAfile
#=====
on horodateur(une_date)
tell une_date to return (((its year) * 10000 + (its month) * 100 + (its day)) as text) & "_" & text 2 thru -1 of ((1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as text)
end horodateur
#=====
may be used as a starting point.
Yvan KOENIG (VALLAURIS, France) vendredi 12 septembre 2014 19:49:39