Why is this script 'openin' stationery files.
Why is this script 'openin' stationery files.
- Subject: Why is this script 'openin' stationery files.
- From: KOENIG Yvan <email@hidden>
- Date: Sat, 10 Sep 2011 09:36:36 +0200
Hello
Here is a script which I wrote to convert standard documents into stationeries so that the original will not be modified by the Lion's Autosave feature wheb we use it.
--{code}
--[SCRIPT set_stationery]
(*
Enregistrer le script en tant que Script : set_stationery.scpt
déplacer le fichier ainsi créé dans le dossier
<VolumeDeDémarrage>:Utilisateurs:<votreCompte>:Bibliothèque:Scripts:
Aller au menu Scripts , choisir “set_stationery”
Naviguer pour sélectionner le document à convertir en modèle.
On peut également enregistrer en tant qu’application.
Dans ce cas,
double cliquer puis naviguer pour sélectionner le document à convertir en modèle.
ou
glisser déposer l’icône du document à convertir sur celle de l'application
Si vous définissez la property add_TM comme true, le caractère ™ sera inséré à la fin du nom du document converti pour faciliter son repérage.
--=====
L’aide du Finder explique:
L’Utilitaire AppleScript permet d’activer le Menu des scripts :
Ouvrez l’Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case “Afficher le menu des scripts dans la barre de menus”.
Sous 10.6.x,
aller dans le panneau “Général” du dialogue Préférences de l’Éditeur Applescript
puis cocher la case “Afficher le menu des scripts dans la barre des menus”.
--=====
Save the script as a Script: set_stationery.scpt
Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:
Go to the Scripts Menu, choose “set_stationery”
Navigate then select the document to convert.
You may also save as an application.
In this case :
double clic the app’s icon to navigate then select the document to convert.
or
drag and drop the icon of the document to convert upon the app’s icon
If you set the property add_TM to true, the character ™ will be inserted at the end of the filename allowing you to quickly identify stationeries.
--=====
The Finder’s Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the “Show Script Menu in menu bar” checkbox.
Under 10.6.x,
go to the General panel of AppleScript Editor’s Preferences dialog box
and check the “Show Script menu in menu bar” option.
--=====
Yvan KOENIG (VALLAURIS, France)
2011/09/08
*)
--=====
property add_TM : false
(*
true = insert the character ™ at the end of the filename
false = leave the name untouched
*)
property un_document : ""
--=====
on run
set un_document to ((choose file without invisible) as text)
run script main
end run
--=====
script main
(*
Use the property un_document *)
local type_id
tell application "System Events" to set type_id to type identifier of disk item un_document
if type_id is "com.apple.iwork.keynote.key" then
(*
Convert a Keynote document *)
tell application "System Events" to tell disk item un_document to set name to (text 1 thru -4 of (get name) & "kth")
else if type_id is "com.apple.iwork.numbers.numbers" then
(*
Convert a Numbers document *)
tell application "System Events" to tell disk item un_document to set name to (text 1 thru -8 of (get name) & "nmbtemplate")
else if type_id is "com.apple.iwork.pages.pages" then
(*
Convert a Pages document *)
tell application "System Events" to tell disk item un_document to set name to (text 1 thru -6 of (get name) & "template")
else if type_id is in {"com.apple.iwork.keynote.kth", "com.apple.iwork.numbers.template", "com.apple.iwork.pages.template", "com.apple.rtfd"} then
(*
Skip Keynote, Numbers, Pages templates as well as rtfd documents *)
set un_document to ""
error number -128
else
tell application "System Events"
try
tell disk item un_document
if not stationery then
set stationery to true
if add_TM then
(*
Optionally insert ™ at the end of the filename to easily recognize templates *)
set name_extension to name extension
if name_extension is "" then
set name to name & " ™"
else
set name to (text 1 thru -(2 + (count of name_extension)) of (get name) & " ™." & name_extension)
end if -- name_extension
end if -- add_TM
end if -- not stationery
end tell -- disk item…
end try
end tell -- System Events
end if -- type_id
(*
Clean the storage property *)
set un_document to ""
end script
--=====
on open sel
set un_document to (first item of sel) as text
run script main
end open
--=====
--[/SCRIPT]
--{code}
When I drag and drop on it the icon of a file which is already a stationery, the script 'opens' this one and create a new document.
And I don't understand which instruction is doing that. It doesn't do that when I trigger the script by a double click using Choose file to select the file.
I guess that it's linked to the structure 'droplet' because I get the same behavior with the bare :
on open sel
--
end open
Yvan KOENIG (VALLAURIS, France) samedi 10 septembre 2011 09:36:30
_______________________________________________
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