Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.5: Set Time Machine disk via AppleScript. problem: language (German)' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Set Time Machine disk via AppleScript. problem: language (German)
Authored by: ronnyHH on Aug 15, '08 11:09:16PM

I have some experience doing this. Is this problem still unsolved? If so, give me me what you have so far. I got somehow the same thing to do with AS and don´t want to start from scratch.

Ronald



[ Reply to This | # ]
10.5: Set Time Machine disk via AppleScript. problem: language (German)
Authored by: tmaeder on Aug 16, '08 01:39:59PM
I have changed the script, which now should work in English, French, German, Italian and Spanish. It finds out the language from the localised name of the System Preferences application, and (sorry for the imperfect translations!) attempts to work in that language.
Also, it now allows for a preferred backup volume (1st in list) and an arbitrary list of allowed backup volumes (no defined priority), and exits gracefully from System Preferences in case of failure by "clicking" on the Cancel button.
Try it out - and have fun! T.M.






(* Original source : http://www.macosxhints.com/article.php?story=20080105135511764 *)


(* This is a script to automatically choose which volume to have time machine back up to. If the primary volume (= 1st in the list) is available, it will be chosen, otherwise it will choose any volume available in the list. If none is available, it will make no changes to the time machine preferences.

To use, set the names of the volumes here : *)

set backup_drives to {"preferred", "backup2", "backup3"}

(*
Then launch the script whenever you want to change the time machine backup. The excellent utility DSW (http://www.azarhi.com/) can be used to launch the script whenever a volume is mounted or unmounted.

The script attempts to use growl to notify the user of its results.

Note that GUI scripting must be enabled
*)


(* User interface elements required for UI scripting
Élments de l'interface utilisateur ncessaire à son pilotage
Für die Steuerung nötige Elementen der Benützeroberfläche
Elementi della interfaccia utente necessari per pilotare l'applicazione
Elementos de la interfacia necesarios para pilotar l'aplicacion *)

(* Lists / listes / Listen / liste / listas : 1) english, 2) français, 3) deutsch, 4) italiano 5) español *)

(* Application (EN)
Application (FR)
Applikation (DE)
Applicazione (IT)
Aplicacion (ES) *)

property names_prefs : {"System Preferences",
"Prfrences Système",
"Systemeinstellungen",
"Preferenze di Sistema",
"Preferencias del Sistema"}


(* Time machine *)

property names_tm : {"Time Machine",
"Time Machine",
"Time Machine",
"Time Machine",
"Time Machine"}


(* Preference pane list menu (EN)
Menu des panneaux de prfrences (FR)
Menu der Einstellungenfenster (DE)
Menu dei paneli di preferenze (IT)
Menu de las panelas da preferencias (ES) *)

property names_view : {"View",
"Prsentation",
"Einstellungen",
"Vista",
"Visualización"}


(* Disc selection button (EN)
Bouton de slection du disque (FR)
Speicherauswahltaste (DE)
Bottone di schelta del disco (IT)
Botón di seleccion del disco (ES) *)

property names_usebutton : {"Use for Backup",
"Slectionner",
"Für backup verwenden",
"Utilizza per backup",
"Usar para copia de seguridad"}


(* Cancel button (EN)
Bouton d'annulation (FR)
Abbrechtaste (DE)
Bottone di annulatione (IT)
Botón di cancelatión (ES) *)

property names_cancelbutton : {"Cancel",
"Annuler",
"Abbrechen",
"Annula",
"Cancelar"}


(* Quit command (EN)
Commande pour quitter (FR)
Beenden-Befehl (DE)
Istruzione per escire (IT)
Comando per salire (ES) *)

property names_quit : {"Quit System Preferences",
"Quitter Prfrences Système",
"Systemeinstellungen Beenden",
"Esci da Preferenze di Sistema",
"Salir de Preferencias del Sistema"}


(* General notification (EN)
Notification gnrale (FR)
Allgemeine Meldung (DE)
Notificazione generale (IT)
Notificación general (ES) *)

property msgs_general : {"General notification",
"Notification gnrale",
"Allgemeine Meldung",
"Notificazione generale",
"Notificación general"}


(* Error notification (EN)
Notification d'erreur (FR)
Fehlermeldung (DE)
Notificazione di errore (IT)
Notificación de error (ES) *)

property msgs_error : {"ERROR",
"ERREUR",
"FEHLER",
"ERRORE",
"ERROR"}


(* Success message (EN)
Message de succès (FR)
Erfolgsmeldung (DE)
Messagio di riuscita (IT)
Mensaje de xito (ES) *)

property msgs_newvolume : {"The Time Machine backup volume is now ",
"Le volume de sauvegarde de Time Machine est maintenant ",
"Der Zielspeicher für Time Machine ist nun ",
"Il disco di backup per Time Machine ora ",
"El disco de copia de seguridad de Time Machine es ahora "}


(* Error message (EN)
Message d'erreur (FR)
Fehlermeldung (DE)
Messagio di errore (IT)
Mensaje de error (ES) *)

property msgs_notchanged : {"Time Machine preferences were not changed",
"Les prfrences de Time Machine n'ont pas t changes",
"Die Einstellungen von Time Machine wurden nicht geändert",
"Le preferenze di Time Machine non sono venuti cambiate",
"Las preferencias de Time Machine no han sido cambiadas"}


(* Language not found message *)

property msg_language : "ERROR - language not found" & return &
"ERREUR - langue non trouve" & return &
"FEHLER - Sprache nicht gefunden" & return &
"ERRORE - lingua non trovata" & return &
"ERROR - lingua no trovada"


property growl_general : "General Notification" -- Growl notification types
property growl_debug : "Debug Notification"
property growl_error : "Error Notification"


register_growl() -- register with Growl notification system



activate application "System Preferences" -- activate or launch preferences


tell application "System Events" -- get the localized_name of the System Preferences application
set loc_name to displayed name of process named "System Preferences"
end tell

global lg -- allow language index to be accessed from subroutines

set lg to 0 -- find out the language used by system preferences
repeat with i from 1 to count names_prefs
if item i of names_prefs = loc_name then
set lg to i
exit repeat
end if
end repeat

if lg = 0 then -- language not found - exit with error
growlnote(growl_error, item 1 of msgs_error, msg_language)
else

set name_tm to item lg of names_tm -- get name of Time Machine because it is used quite often

tell application "System Events"
tell process "System Preferences"
click menu item name_tm of menu 1 of menu bar item (item lg of names_view) of menu bar 1 -- directly activate Time Machine panel from menu

repeat until exists window name_tm
delay 0.2
end repeat
click button 1 of group 1 of window name_tm -- change disk button

(* Choose 1st available disk *)
repeat until exists sheet 1 of window name_tm -- wait till disk change dialog comes up
delay 0.2
end repeat

set tablecontents to (rows of table 1 of scroll area 1 of sheet 1 of window name_tm) -- traverse disk list
set rownumber to 0
set desiredrownumber to 0 -- reset row number (in volume list) of desired volume
set desired_name to "" -- reset desired volume name
set preferred_name to item 1 of backup_drives -- get name of the preferred / primary backup volume = 1st in the list
repeat with tablerow in tablecontents
set rownumber to rownumber + 1
set volumename to (value of static text of row rownumber of table 1 of scroll area 1 of sheet 1 of window name_tm) as string
log volumename
if (volumename as string) is in backup_drives then -- found a volume in the list
set desiredrownumber to rownumber -- set the desired row number in volume list
set desired_name to volumename -- set the desired volume name
if desired_name = preferred_name then exit repeat -- keep this one if this is the primary volume
end if
end repeat
if desiredrownumber > 0 then
try
select row desiredrownumber of table 1 of scroll area 1 of sheet 1 of window name_tm -- select the desired volume in list
click button (item lg of names_usebutton) of sheet 1 of window name_tm -- click the localised "use" button
set message_title to (item lg of msgs_general) -- tell user that a backup volume has been successfully selected
set message to (item lg of msgs_newvolume) & desired_name
my growlnote(growl_general, message_title, message)

on error
set desiredrownumber to 0 -- if failure for some reason, reset row number to 0 = nothing
end try
end if

if desiredrownumber = 0 then -- error message if unsuccessful
try -- try to cancel
click button (item lg of names_cancelbutton) of sheet 1 of window name_tm -- click the localised "Cancel" button
end try
set message_title to (item lg of msgs_error) -- not found : tell user that the preferences weren't changed
set message to item lg of msgs_notchanged
my growlnote(growl_error, message_title, message)
end if

delay 1 -- wait for a confirmation dialog that appears if you select a partition on the same physical disk as that being backed up
if (exists button (item lg of names_usebutton) of window 1) then
click button (item lg of names_usebutton) of window 1
end if


click menu item (item lg of names_quit) of menu 1 of menu bar item (item lg of names_prefs) of menu bar 1 -- quit preferences
end tell
end tell
end if




(* Try to register script with Growl *)

on register_growl()
try
tell application "GrowlHelperApp"
set the allNotificationsList to {growl_general, growl_debug, growl_error} -- Growl notifications
set the enabledNotificationsList to {growl_general, growl, debug, growl_error} -- Those enabled for this app
register as application "Configure TimeMachine" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "TimeMachine"
end tell
end try
end register_growl

on growlnote(growltype, msg_title, msg_text)
try
tell application "GrowlHelperApp"
notify with name growltype title msg_title description msg_text application name "Configure TimeMachine"
end tell
end try
end growlnote

[ Reply to This | # ]