• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Autosave Numbers document
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Autosave Numbers document


  • Subject: Re: Autosave Numbers document
  • From: "koenig.yvan" <email@hidden>
  • Date: Fri, 12 Sep 2014 19:49:43 +0200


Le 12/09/2014 à 17:46, okn <email@hidden> a écrit :


Hi & good day,

A script to save a document, got it from Mac World where they used MS Word.

But for Numbers it seems this app needs something else.

Where in the Library would I have to look?



# Autosave Numbers document, MW 2014-09-12 
tell application "Numbers.app"
if it is running and name of active document does not contain "Document" then
save active document
end if
end tell

—> error: 

Expected then but found class name.

But then is there.


Hello, the error message is wrong.
The problem is that quite everything is wrong in your script.

(1)
Don’t write : 
tell application "Numbers.app"
but
tell application "Numbers"
(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
 _______________________________________________
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

  • Follow-Ups:
    • Re: Autosave Numbers document
      • From: "koenig.yvan" <email@hidden>
References: 
 >Autosave Numbers document (From: okn <email@hidden>)

  • Prev by Date: Autosave Numbers document
  • Next by Date: Re: Autosave Numbers document
  • Previous by thread: Autosave Numbers document
  • Next by thread: Re: Autosave Numbers document
  • Index(es):
    • Date
    • Thread