Archive of articles classified as' "Softwareschmiede"

Back home

Unterschriften-Erfassung via Web-Viewer in Filemaker

24/01/2012

Ein Bekannter von mir wollte sich eine Filemaker-Datenbank aufbauen, mit der Mitarbeiter papierlos den Empfang von Paketen quittieren können sollten und das mittels Wacom-Tablet und Filemaker.
Read the rest of this article »

No Comments

Address Book: Normale Gruppen von Smart-Groups unterscheiden

15/01/2012
In den Adress-Buch-Funktionsverzeichnis gibt es als Property nur den Namen und leider keinen Wert den man auslesen könnte, um zu erkennen, ob es sich um eine Smart-Group oder eine echte Gruppe handelt. Um das nun doch zu können sind zumindest die jeweiligen IDs der Gruppe recht eindeutig und enden ggf. mit dem String "SmartGroup". Möchte man zum Beispiel alle Namen der normalen Gruppe:

tell application "Address Book"

set groupnames to name of every group whose id does not end with "SmartGroup"

end tell

No Comments

PDF: Dynamisches Wasserzeichen mit SVG->PDF Overlay

11/12/2011

Ich habe einen neuen Trick gefunden automatisch PDFs zu erstellen, ohne dabei auf allzu teure (Indesign, Quark), komplizierte (ruby pawn z.B.) oder nicht gerade performante Tools (Pages, Word) angewiesen zu sein. SVG-Dateien sind quasi nichts anderes als XML bzw. Text-Dateien, und lassen sich leicht per Skript manipulieren. Zudem lassen sich auch exakte Format-Angabe (A4, Letter usw.) definieren.

Das Wandeln von SVG in PDF übernimmt dann Inkscape und zwar als Shell-Anwendung. Auf diese Art lassen sich schnell (ohne GUI) PDFs erstellen, die anders als bei der wkpdf-Lösung auch über einen Transparente Hintergrund verfügen.
Ich habe jetzt kein direktes Beispiel zur Hand, verweise aber mal /Applications/Inkscape.app/Contents/Resources/bin/inkscape-bin --help

1 Comment

Mail: Bewege flagged Emails in Ordner XY

11/12/2011

Es ist schon erstaunlich, dass es keine Regel in Apple Mail zu geben scheint, mit der man markierte (diese kleine rote Flage) Emails automatisch in einen anderen Ordner verschieben kann... hm Vielleicht weil die Regeln in der Regel nur auf neue Emails angewendet werden, die von Natur aus nicht markiert sind...
Nun, diese Skript springt sofort auf markierte E-Mails an und verschiebt diese in definierbaren Ordner. In den Einstellungen die am Anfang des Skriptes gemacht werden können, kann der Account-Name, die zu durchsuchenden Ordner (Plural!) und der Zielordner angegeben werden. Um auch verschachtelte Ordner als Quelle oder Ziel angeben zu können, werden diese "Pfade" als Liste eingegeben... Erläuterung im Quelltext...
Ein netter Zusatz ist die Abfrage, ob Mail überhaupt läuft. So wird ein unfreiwilliger Start von Mail durch das Skript (z.B. via crontab) verhindert.

--10.12.2011 hubionmac.com

--Beweg Emails die markiert sind in einen anderen Ordner

-- In den Prefs können als Quelle mehrere Ordner angegeben werden

-- Unterordner werden in Form einer Liste angegeben z.B. um den Ordner Bla im Ordner Fasel anzugeben -> {"Fasel","Bla"}

--Beim Ziel-Ordner kann wahlweise angegeben werden, ob es sich um einen lokal oder ggf. um einen IMAP-Ordner des jeweiligen Accounts handelt


set theprefs to

{AccountName:"hubionmac.com", SourceFolders:{{"INBOX"}, {"Archive", "Kleiner Test"}}, DestinationFolder:{"Sammel", "Lager"}, DestinationFolderIsLocal:false}, ¬

{AccountName:"gmx.net", SourceFolders:{{"INBOX"}, {"bla", "blafasel"}}, DestinationFolder:{"Sammel", "Lager"}, DestinationFolderIsLocal:false} ¬

}

--prüfer erst mal ob Mail läuft… denn extra gestartet werden soll es deswegen mal nicht

tell application "System Events"

set MailIsRunning to (count of (every process whose bundle identifier is "com.apple.mail")) > 0

end tell

end

if MailIsRunning then

tell application "Mail"

repeat with todo in theprefs

set AccountName to AccountName of todo

set SourceFolders to SourceFolders of todo

set DestinationFolder to DestinationFolder of todo

set islocal to DestinationFolderIsLocal of todo

set TheDestinationFolder to my getFolderReference(AccountName, DestinationFolder, islocal)

repeat with SourceFolder in SourceFolders

set TheSourceFolder to my getFolderReference(AccountName, SourceFolder, false)

-- get the mails that are interesting

set themails to (every message of TheSourceFolder whose flagged status is true)

--movethemails

repeat with themail in themails

move themail to TheDestinationFolder

end repeat

end repeat

end repeat

end tell

end if


on getFolderReference(AccountName, DestinationFolder, isAlwayslocal)

tell application "Mail"

set TheDestinationFolder to ""

set islocal to (get account type of account AccountName is pop)

if isAlwayslocal = true then set islocal to true

repeat with FolderName in DestinationFolder

if islocal then

if FolderName as string ≠ "INBOX" then

if TheDestinationFolder = "" then

set TheDestinationFolder to mailbox FolderName

else

set TheDestinationFolder to mailbox FolderName of TheDestinationFolder

end if

else

set TheDestinationFolder to mailbox FolderName of account AccountName

end if

else

if TheDestinationFolder = "" then

set TheDestinationFolder to mailbox FolderName of account AccountName

else

set TheDestinationFolder to mailbox FolderName of TheDestinationFolder

end if

end if

end repeat

return TheDestinationFolder

end tell

end getFolderReference

Um das Skript immer mal wieder ablaufen zu lassen, kann man z.B. den crontab nutzen. Dazu am einfachsten via CronniX einen solchen für den aktuellen Nutzer einrichten und das Script mit dem Befehl osascript /Pfad/zur/.scpt-Datei alle x-Minuten laufen lassen. Wie so ein Intervall einzurichten ist, wird sehr gut in der Cronnix-Hilfe erläutert. (was lange währt wird endlich programmiert Thorkillar :-) )

No Comments

Episoden Benenner – Episode Namer

9/12/2011

Ich bin ja leidenschaftlicher Serien-Gucker, nur das Bennen der aufgezeichneten Sendungen nervt auf Dauer. Deshalb habe ich mir ein kleines Skript gebaut, mit dem sich die Dateien quasi von selber umbenennen.
Das läuft so ab, die Dateien haben meist schon eine teilweise korrekte Namensgebung, z.B. die Laufende Nummer (Folge 23.mp4) oder "S01E03.mp4" oder einfach direkt der Titel "Mr Monk unterwegs als Weihnachtsmann.mp4". Jetzt habe ich mir von meinen Lieblings-Serien Episoden-Listen erstellt in der Form: LaufendeNummer → Season Nummer → EpisodenNummer → Episoden Titel als tab separierte Text-Datei. Diese Benutzt dann das Skript zum erstellen eines Index. Jetzt muss ich nur noch die Datei auf das Skript ziehen, angeben um welche Serie es sich handelt, woran das Skript die jeweilige Episode erkennen kann und wie ich die Episoden benannt haben möchte... zack sind 100 Episoden entsprechend benannt. Zur Sicherheit speichert das Skript aber auch noch den alten Dateinamen im Kommentar der Datei ab.

DOWNLOAD
Episode Benenner v.1.0
95.06 kB (23 hits)
2 Comments

AppleScript Reste-Eintopf II

9/12/2011

Add to Login-Items

--03.09.2008 hubionmac.com

--asks for an app and adds it to login items

addtologin(choose file of type {"APPL"})

on addtologin(thisApp) -- adds an item to login items

set appPath to POSIX path of thisApp

tell application "System Events"

set appName to name of thisApp

set shortName to (characters 1 through ((get offset of ".app" in appName) - 1) of appName) as text

if shortName is not in (name of every login item) then

make login item at end with properties {path:appPath}

end if

end tell

end addtologin

Nach Datei-Endungen sortieren

Das hatte ich mal als Ordner-Aktion für meinen Download-Ordner erdacht... seitdem es Spotlight gibt, hat der Drang Downloads zu sortieren deutlich nachgelassen ;-)

--19.11.2006 hubionmac.com

--Ordneraktion die Dateien an Hand Ihrer Datei-Endung in Unter-Ordner sortiert

on adding folder items to derOrdner after receiving added_items

-- die Liste kann man gut erweitern

set endungmitordner to {".jpg;JPEGS", ".mov;Movies"}

repeat with k in endungmitordner

--damit kann man die Einträge aus der Liste gut in Ihre Bestandteile zerlegen

--Ist auch super um in Strings Teile zu ersetzen =)

set AppleScript's text item delimiters to ";"

set endung to text item 1 of k

set ordnername to text item 2 of k

set AppleScript's text item delimiters to ""

tell application "Finder"

set inhalt to every item of derOrdner

set itemcount to count of every item of inhalt

-- wenn in dem Ordner nix drin ist, soll er auch nix machen... lohnt ja nicht

if itemcount > 1 then

repeat with aitem in inhalt

--Die Anzahl der Buchstabe einer definierten Endung... damit ich am Ende auch weiß ob ich nach

-- .tiff oder .mov suchen muss

set endcount to (-1 * (count of every character of endung))

set itemname to name of aitem

if (characters endcount through -1 of itemname) as text = endung then

--wenn es den ordner schon gibt den fehler ignorieren und weiter im Text

try

make folder at derOrdner with properties {name:ordnername}

end try

--wir basteln uns einen Alias zu einem Verzeichnis

set workingdir to ((derOrdner as string) & ordnername & ":") as alias

--tja und dieser teil bewegt die Datei in den Ordner... und bennent sie um, sofern der

--Name bereits im Zielordner existiert

-- man könnte statt des counters auch die uhrzeit bzw. das datum nehmen...

-- oh ich neheme die Uhrzeit =).

try

move aitem to workingdir as alias

on error

set no_error to false

repeat until no_error = true

set counter to (time of (current date))

try

set name of aitem to (counter & "##" & itemname) as string

move aitem to workingdir as alias

set no_error to true

exit repeat

on error

set no_error to false

end try

end repeat

end try

end if

end repeat

end if

end tell

end repeat

end adding folder items to

Safari Bookmark Saver

Man nehme den Titel und die URL der aktuellen Seite und speichere sie via Skript in einer kleinen HTML-Datei (meta-refresh)... fertig ist das Platform-übergreifende Bookmark-File

--18.01.2005

--Safari Bookmark safer

-- it's not a boookmark but a tiny html file that redirects to the saved URL

set html_text01 to "<html><meta http-equiv=\"refresh\" content=\"0; URL="

set html_text02 to "\"></html>"


tell application "Safari" to set windowcount to count of every window

if windowcount ≥ 1 then

tell application "Safari" to set theurl to URL of document 1

tell application "Safari" to set thename to name of document 1

display dialog "Filename" default answer thename

set thename to text returned of the result

set thetext to html_text01 & theurl & html_text02 as text

do shell script "echo " & quoted form of thetext & "|cat >~/Desktop/" & quoted form of thename & ".html"

end if

Folder-List

Erstelle eine Art Folder-Map... keine Ahnung wofür ich das mal brauchte...

-- 18.3.2007 hubionmac.com.com

-- creates a table of contents (tree structure) of  a folder that was dropped onto the script and saves it into a text file

global theroottxt, thefolder_unix, tabcount

on open thefolder

if (count of thefolder) > 1 then

display dialog "Please put ONE Folder onto the script"

end if

set thefolder to thefolder as alias

set thefolder_unix to POSIX path of thefolder

set theroottxt to thefolder as text

tell application "Finder"

set these_folders to every folder of thefolder

end tell

set tabcount to 0

repeat with this_folder in these_folders

set folderstring to get_folderstring(this_folder)

do shell script ("echo " & quoted form of folderstring & "|cat>> " & quoted form of thefolder_unix & "folder_list.txt") as text

do_folder(this_folder)

end repeat

end open




on do_folder(this_folder)

set tabcount to tabcount + 1

tell application "Finder"

set these_folders to every folder of this_folder

end tell

repeat with this_folder in these_folders

set folderstring to get_folderstring(this_folder)

do shell script ("echo " & quoted form of folderstring & "|cat>> " & quoted form of thefolder_unix & "folder_list.txt") as text

do_folder(this_folder)

end repeat

set tabcount to tabcount - 1

end do_folder



on get_folderstring(this_folder)

tell application "Finder"

set FolderName to name of this_folder

end tell

repeat with i from 1 to tabcount

set FolderName to tab & FolderName

end repeat

return FolderName as text

end get_folderstring

Rekursions-Beispiel

Würde ich heute ehr mit find -type d lösen, aber geht auch so

--12.10.2005 hubionmac.com

--Beispiel zum Thema Rekursion

global folderkind


set thisfolder to choose folder

display dialog "deepcount=" default answer "0"

set deepcount to text returned of the result as integer

if deepcount = 0 then

process_item(thisfolder)

else

process_folder(thisfolder, deepcount)

end if


on process_folder(this_item, deepcount)

tell application "Finder"

set these_items to every folder of this_item

set deepcount to deepcount - 1

end tell

repeat with this_item in these_items

if deepcount = 0 then

process_item(this_item)

else

process_folder(this_item, deepcount)

end if

end repeat

end process_folder


on process_item(this_item)

tell application "Finder"

set itemname to name of this_item

display dialog itemname

end tell

end process_item

No Comments

PDF: Dynamisches Wasserzeichen mit HTML->PDF Overlay

9/12/2011

Bevor ihr weiterlest (Update: 11.12.2011):

Das mit dem HTML-Dokument als Print-Vorlage war nur ein ehr mittelmäßiger Ansatz... glücklicherweise hat sich eine neue Möglichkeit aufgetan, wie man PDFs von einer besseren Formatvorlage (SVG) erstellen kann. Mehr dazu hier

Ich habe eine relative elegante Lösung gefunden, wie man PDFs mit ein paar Tricks mit dynamischen Wasserzeichen versehen kann. Bei der ursprünglichen Aufgabenstellung wollte jemand Daten aus einem Numbers-Sheet auslesen und dementsprechend Logos und Texte als Wasserzeichen zu PDFs hinzufügen.

Das mit dem Wasserzeichen ist ja mit pdftk recht leicht zu bewerkstelligen und auch das abgleichen der Daten mit den PDF-Namen war ein leichtes. Etwas schwieriger war da schon das automatische Layouten der Datensätze in ein PDF. Man kann so etwas bestimmt mit Quark oder Indesign machen, nur stehen mir diese Programme leider nicht zu Verfügung und zudem produzieren die Dinger einen ganz schönen Overhead und der Rechner ist in der Zeit komplett blockiert.

Stattdessen habe ich mir für einen günstigere Variante (php, ruby-> wkpdf) quergedacht, da die PDFs sowieso nur für den Online-Gebrauch erstellt werden sollen und nicht für den Druck.

Read the rest of this article »
1 Comment

AppleScript Reste-Eintopf

4/12/2011

Ich räume gerade meine AppleScript-Verzeichnis auf und dabei sind mir einige Code-Schnipsel untergekommen, die noch nicht hier "archiviert" wurden:

convert aliases into symlinks:

Damit lassen sich wunderbar Aliase in symbolische Links umwandeln. Macht z.B. Sinn, wenn man schnell via Finder Aliase anlegt, die Software, die aber die Dateien braucht nur mit symbolischen Links klar kommt.

set thefolder to choose folder

set thefolderx to POSIX path of (thefolder as alias)

tell application "Finder"

set thealiases to every alias file of thefolder

repeat with thisalias in thealiases

set aliasname to name of thisalias

set theorig to original item of thisalias

set theorigx to POSIX path of (theorig as alias)

do shell script "cd " & quoted form of thefolderx & ";rm " & quoted form of aliasname & ";ln -s " & quoted form of theorigx & " " & quoted form of aliasname

end repeat

end tell

DropTar:

Ich wollte wohl mal via Drag&Drop bzw. eine Finder-Auswahl einfach als .tar.gz packen.... hat sich dank LaunchBar bei mir nun erledigt (da ist so etwas schon eingebaut), der Code landet nun hier

on open these_items

my makeTar(these_items)

end open

on run

tell application "Finder"

set these_items to selection

if these_items = {} then error "Nothing slected"

my makeTar(these_items)

end tell

end run


on makeTar(these_items)

-- READ THE NAME

display dialog "Name of the file:" default answer "" buttons {".TAR", ".TAR.GZ", "cancel"}

copy result as list to dialog01

set tarname to item 1 of dialog01

if tarname = "" then

display dialog "please enter a propper name!" buttons {"cancel"}

else

if (item 2 of dialog01) as text = ".TAR" then

set tarname to (tarname & ".tar") as text

set zz to "-"

else if (item 2 of dialog01) as text = ".TAR.GZ" then

set tarname to (tarname & ".tar.gz") as text

set zz to "-z"

end if

end if

-- READ THE LOCATION WHERE THE FILE SHOULD BE STORED

set save_path to POSIX path of (choose folder with prompt "Where do you wanna save " & tarname & "?")

set thefiles to ""

set first_item to true

repeat with this_item in these_items

tell application "Finder"

-- READ THE FILE's LOCATIONS AND COMPARE THEM

set current_container to container of this_item

if first_item = true then

set item_container to current_container

set first_item to false

end if

-- if the current_containter does not match the general container ERROR!

if item_containercurrent_container then

display dialog "Sorry, this script can only proccess files/folders that at the same location" buttons {"cancel"}

else

-- GET THE ITEMS' NAMES AND LIST THEM

set item_name to name of this_item

set thefiles to thefiles & " \"" & item_name & "\""

end if

end tell

end repeat

-- GET THE POSIX PATH OF THE ITEMS ' CONTAINER

set thefilespath to quoted form of POSIX path of (item_container as alias)

-- MAKE THE COMMAND STRING FOR THE SHELL

set theshellcommand to ("cd " & thefilespath & "; tar " & zz & "cf " & quoted form of ((save_path & tarname) as text) & thefiles) as text

set the clipboard to theshellcommand

-- display dialog theshellcommand

-- DO THE SHELL COMMAND, BECAUSE THIS COULD TAKE SOME TIME... A LONG TIMEOUT SO NO APPLE EVENT TIMEOUT POPS UP =)

with timeout of 3600 seconds

do shell script theshellcommand

end timeout

end makeTar

dmg-maker:

Und hier wollte ich mal per AppleScript ein dmg-Image erstellen...

on open these_

if (count of these_) > 1 then

tell me to quit

end if

tell application "Finder"

set orig_image to quoted form of (POSIX path of item 1 of these_)

set imagename to quoted form of ((name of (item 1 of these_)) as text)

set image_destination to quoted form of POSIX path of (folder of ((item 1 of these_) as alias) as alias)

end tell

set thecommand to ("hdiutil convert " & orig_image & " -format UDZO -imagekey zlinb-level=9 -o " & image_destination & imagename & ".dmg") as text

tell application "Terminal"

run

delay 1

do script with command thecommand

end tell

end open


delete empty folders

Leere Ordner haben mit dem Code fast nichts zu lachen... funktioniert auch nur auf einer Ebene ist also nicht rekursiv geschrieben

on open hubi

tell application "Finder"

set folderkind to kind of folder 1 of startup disk

repeat with k in hubi

if kind of k = folderkind then

set itemcount to count of every item of k

if itemcount = 0 then

delete k

end if

end if

end repeat

end tell

end open


tell application "Finder"

set hubi to selection

set folderkind to kind of folder 1 of startup disk

repeat with k in hubi

if kind of k = folderkind then

set itemcount to count of every item of k

if itemcount = 0 then

delete k

end if

end if

end repeat

end tell

delete n chars at beginning/end of filename

tell application "Finder"

set hubi to selection

set folderkind to kind of folder 1 of startup disk

repeat with k in hubi

if kind of k = folderkind then

set itemcount to count of every item of k

if itemcount = 0 then

delete k

end if

end if

end repeat

end tell

delete .DS_Store

Die Dateien machen oft so gar keinen Sinn und stören mich einfach unter Windows.

set thepath to POSIX path of (choose folder)

set hubi to do shell script "cd " & quoted form of thepath & ";find ./ -name .DS_Store -delete"

display dialog ".DS_Store deleted"

Dateien nach Erstellungsdatum in Ordner sortieren

Ich glaube das war mal ein Versuch meinen Download-Ordner etwas aufgeräumter aussehen zu lassen... alles nur Schein ;-)

--hubionmac.com >~2007 i think

--AppleScript Droplet to sort fieles into folders by creation date

on open these_items

set thelist to {make_dateString(current date, 1)} & {make_dateString(current date, 2)} & {make_dateString(current date, 3)} as list

choose from list thelist with prompt "Choose date format:"

if result as text = item 1 of thelist as text then

set theformat to 1

else if result as text = item 2 of thelist as text then

set theformat to 2

else if result as text = item 3 of thelist as text then

set theformat to 3

end if

repeat with this_item in these_items

tell application "Finder"

-- set thedate to creation date of this_item

set thedate to modification date of this_item

set theLocation to quoted form of POSIX path of ((folder of this_item) as alias)

end tell

set foldername to make_dateString(thedate, theformat)

try

do shell script "cd " & theLocation & ";mkdir " & quoted form of foldername

end try

set the_item to quoted form of POSIX path of this_item

-- 2008-05-26 -n Option add, so files are not overwritten

do shell script "cd " & theLocation & ";mv -n " & the_item & " ./" & quoted form of foldername & "/"

end repeat

end open



on get_month_number(incomingDate)

-- works with systems <OS X 10.4

copy incomingDate to b

set the month of b to January

set month_number to "0" & (1 + (incomingDate - b + 1314864) div 2629728) as text

return (characters -2 through -1 of month_number) as text

end get_month_number


on make_dateString(thedate, theformat)

if theformat = 1 then

set theday to characters -2 through -1 of (("0" & day of thedate) as text) as text

set thestring to (year of thedate) & "-" & get_month_number(thedate) & "-" & theday

else if theformat = 2 then

set thestring to (year of thedate) & "-" & get_month_number(thedate)

else if theformat = 3 then

set thestring to (year of thedate)

end if

return thestring as text

end make_dateString



Rechner ausschalten nach x-Minuten

Das funktioniert, wenn kein Dialog aufgeht... ansonsten müsste man das mit shutdown -now und Admin-Rechten machen...

with timeout of 600000 seconds

display dialog "Shutdown in x Minutes?" default answer 10

set i to (text returned of the result) as integer

delay i * 60

tell application "Finder" to shut down

end timeout

1 Comment

Dateien eines bestimmten Typs verschieben und Ordnerstruktur dabei beibehalten

2/11/2011
Das war die Aufgabenstellung, damit die Ordnerstruktur der Kamera zwar beibehalten wird, jpgs und raw Dateien aber getrennt abgelegt werden:

set thesource to quoted form of POSIX path of (choose folder)

set thedestination to quoted form of POSIX path of (choose folder)

set thesuffix to "'*.jpg'"

set thelist to get_folder_and_file_list(thesuffix, thesource)

set filecount to count of every paragraph of item 2 of thelist

display dialog filecount & " files have been moved" as text


make_folders_of_list(thedestination, every paragraph of (item 1 of thelist))

move_files_to_folders(thesource, thedestination, every paragraph of (item 2 of thelist))


on move_files_to_folders(thesource_folder, destination_folder, filelist)

repeat with thefile in filelist

do shell script "cd " & destination_folder & ";mv " & thesource_folder & quoted form of thefile & " " & quoted form of thefile

end repeat

end move_files_to_folders


on make_folders_of_list(destination_folder, folderlist)

repeat with thefolderpath in folderlist

do shell script "cd " & destination_folder & ";mkdir -p " & quoted form of thefolderpath

end repeat

end make_folders_of_list


on get_folder_and_file_list(searchstring, folder2search)

set folderlist to do shell script "cd " & folder2search & ";find . -iname " & searchstring & " -exec dirname {} \\;"

set filelist to do shell script "cd " & folder2search & ";find . -name " & searchstring

return {folderlist, filelist}

end get_folder_and_file_list

No Comments

Preferences eines Programms sichern/wiederherstellen

17/09/2011
Die eigentliche Idee stammt von hier und dabei herausgekommen ist dieses Skript (Vor dem Ausführen als AppleScript Bundle oder Programm speichern, da es sonst zu Schwierigkeiten mit den Speicherpfad kommt.):

--17.09.2011 hubionmac.com

-- Prefs-Save-Restore_v1: Saves and Restores an app's preferences, Library Folder, Application Support Folder using a tar archive

-- inspired by http://macscripter.net/viewtopic.php?id=37052


-- STORE THIS AS AN APPLICATION OR SCRIPT BUNDLE!!!!

global store_here

--first get the folder where all the saved prefs should be saved….

try

set store_here to quoted form of POSIX path of (path to resource "saved_prefs")

on error msg

do shell script "mkdir " & quoted form of POSIX path of (path to me as alias) & "Contents/Resources/saved_prefs"

--NOT USING PATH TO RESSOURCE BECAUSE IT DOESN'T SEEM TO UPDATE THAT FAST….

set store_here to quoted form of POSIX path of (path to me as alias) & "Contents/Resources/saved_prefs"

end try

-- WHAT TO DO?

set theaction to button returned of (display dialog "Do you want to restore or backup an app Prefs?" buttons {"Restore", "Backup", "Cancel"} default button {"Restore"})

if theaction = "Backup" then

make_backup(choose file of type "app")

else if theaction = "Restore" then

make_restore()

end if


on make_restore()

set thebackups to every paragraph of (do shell script "ls " & store_here)

if thebackups = {} then

error "There are no backups that can be used to restore…."

else

set t to (choose from list thebackups with prompt "Choose one or more backup(s):" default items (item 1 of thebackups) with multiple selections allowed)

if tfalse then

repeat with m in t

do shell script "cd ~/Library; tar xf " & store_here & quoted form of m

my display_message("Restored " & m & ".", 2)

end repeat

end if

end if

end make_restore

on make_backup(this)

set search_folders to {"./", "'Application Support'/", "Preferences/"}

tell application "Finder"

--GET THE IMPORTANT INFOS OUT OF INFO.PLIST FOR GETTING THE NAMES OF PLIST AND OTHER FILES AND FOLDERS INSIDE THE LIBARAY

set this_info_plist to quoted form of POSIX path of (item "Info.plist" of folder "Contents" of this as alias)

set this_id to do shell script "defaults read " & this_info_plist & " CFBundleIdentifier"

set this_bundleName to do shell script "defaults read " & this_info_plist & " CFBundleName"

--THIS LOOKS COMPLICATED BUT IS FASTER THAN USING THE FINDER

--AND IS IS THAT COMPLICATED BECAUSE OF THE OUTPUT OF THE FIND COMMAND THAT NEEDS TO BE QUOTED ;-/

set this_app_files to {}

repeat with search_folder in search_folders

--SEARCH THE SEARCH_FOLDER FOR FILES AND FOLDERS BUT ONLY ON THE FIRST LEVEL!!!

set tmp to every paragraph of (do shell script "cd ~/Library/" & search_folder & "; find . -maxdepth 1 -name '" & this_id & "*' -exec basename {} \\;")

repeat with t in tmp

set this_app_files to this_app_files & ((search_folder & quoted form of t) as text)

end repeat

set tmp to every paragraph of (do shell script "cd ~/Library/" & search_folder & "; find . -maxdepth 1 -name '" & this_bundleName & "' -exec basename {} \\;")

repeat with t in tmp

set this_app_files to this_app_files & ((search_folder & quoted form of t) as text)

end repeat

end repeat

set old_delimiters to AppleScript's text item delimiters

set AppleScript's text item delimiters to " "

set this_app_files to this_app_files as text

set AppleScript's text item delimiters to old_delimiters

--NOW MAKE A TAR FILE OF ALL THESE IN THIS APPS RESSOURCE FOLDER

do shell script "cd ~/Library/; tar -czf " & store_here & this_id & ".tar.gz " & this_app_files

my display_message("Stored " & this_id & ".", 2)

end tell

end make_backup



on display_message(msgTXT, msgTimeout)

tell application "System Events"

set isRunning to ¬

(count of (every process whose name is "GrowlHelperApp")) > 0

end tell

if isRunning = true then

tell application "GrowlHelperApp"

-- Make a list of all the notification types 

-- that this script will ever send:

set the allNotificationsList to ¬

{"Status"}

-- Make a list of the notifications 

-- that will be enabled by default.      

-- Those not enabled by default can be enabled later 

-- in the 'Applications' tab of the growl prefpane.

set the enabledNotificationsList to ¬

{"Status"}

-- Register our script with growl.

-- You can optionally (as here) set a default icon 

-- for this script's notifications.

register as application ¬

"Finder" all notifications allNotificationsList ¬

default notifications enabledNotificationsList ¬

icon of application "Finder"

-- Send a Notification...

notify with name ¬

"Status" title ¬

"Prefs-Safe-Restore" description ¬

msgTXT application name ¬

"Finder"

return true

end tell

else

activate

display dialog msgTXT giving up after msgTimeout

end if

end display_message

No Comments