AppleScript Reste-Eintopf

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

Posted in Useful Snippets | Tagged | 1 Comment

OS X Client unter Parallels installieren (verboten!)

  1. Image von Snow-Leopard bzw. Leopard erstellen (nicht von dem Volumen sondern dabei das Laufwerk selbst auswählen, so kommen alle Infos (Partitionen mit)
    Das Image sollte auch beschrieben werden können
  2. Image Mounten und im Terminal auf dem Image unter (cd /Volumes/Image-Volume-Name)touch System/Library/CoreServices/ServerVersion.plist eine entsprechende Datei anlegen. Dann futtert auch Parallels das Image als wäre es das einer Server-Installation
  3. Image als Installationsmedium in Parallels auswählen und Installation durchführen
  4. Vor dem obligatorischen Neustart nach erfolgter Installation noch bevor der Countdown abgelaufen ist unter Dienstprogramme das Terminal aufrufen und folgende Zeile ausführen touch /Volumes/Macintosh\ HD/System/Library/CoreServices/ServerVersion.plist. So akzeptiert Parallels nach dem Neustart auch die Client-Installation als System
Dadurch verletzt man natürlich die Lizenzbestimmungen von OS X Client, also die Virtuelle Maschine gleich wieder löschen :-P
Posted in OS X | Tagged , | 7 Comments

Dateien eines bestimmten Typs verschieben und Ordnerstruktur dabei beibehalten

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

Posted in AppleScript, Useful Snippets | Leave a comment

PS3-Controler + Mac + GTA San Andreas = rockt

Hätte ich nicht für möglich gehalten, aber es funktioniert. PS3-Controller via USB-Anschließen, abziehen und somit unter Lion am Mac via Bluetooth koppeln. GTA San Andreas (Mac) starten und spielen. Unglaublich aber wahr, es funktioniert out of the Box, nur die Belegung des Controlers muss man etwas anpassen =)!
Posted in Fun, ps3 | Tagged , , | Leave a comment

Mein täglich News

Ist schon interessant wenn man sich den Aufbau einer News-Seite mal unter dem Gesichtspunkt anschaut, wie viel Sinnvolle Informationen direkt beim Laden angezeigt werden, ohne dass man scrollt... Nun MacNews.de will anscheinend nur noch werben und nicht informieren... meine Favoriten was den Aufbau der Seite und vor allen Dingen den Informationsgehalt der Artikel angeht: Macnews.com und Macgadget.de und nach ein paar Abstrichen auch noch MacTechnews.de

Was für Macnews-Seiten könnte man bloß wirklich empfehlen?
Posted in Blafasel, Elender Weltverbesserer | Tagged , , | Leave a comment

Airdrop für alle

defaults write com.apple.NetworkBrowser BrowseAllInterfaces 1; killall Finder
Posted in defaults write | Tagged | 2 Comments

Preferences eines Programms sichern/wiederherstellen

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

Posted in Finder | Tagged , , , | Leave a comment

iCal:Arbeitszeiterfassung die 3.

Sodele ich habe das Skript nun etwas umgeschrieben.
  • das Skript hat nun eine reine Update-Funktion für die Statistik (zur Zeit auf 8 Wochen eingestellt, um bei großen Kalendern die Bearbeitungszeit zur verkürzen)
  • Bei der Statistik werden nun alle nicht-allday-Events berücksichtigt, die eine Dauer größer 1min haben, d.h. Aufgaben werde nun auf die Minute genau erfasst und nicht auf 5min gerundet
  • Die Statstitik wird nun nicht nur für die aktuelle Woche/Monat aktualisiert, sondern für alle Wochen und Monate, die aktuelle Event andauert
  • Das Skript erkennt nun Events an die wie bisher ein Open in der Beschreibung haben, die als Allday-Event angelegt wurden und keine Statistik-Events sind und Events die die gleiche Anfangs- wie Endzeit haben
  • Wählt man ein AllDay-Event zum Abschließen aus, fragt das Skript nach der Anfangs-Uhrzeit des Events.
DOWNLOAD
iCal_Time_Recording_2011_09_15 v.1.3
192.7 kB (156 hits)

@macupdate
@YouTube
Posted in ical, ready2use | Tagged , , | 2 Comments

Dateiliste in Numbers führen an Hand von Dateinamen

Ich habe z.B. in Numbers eine Liste mit allen Job-IDs und möchte in einer Spalte daneben alle Dateien aus einem Bestimmten Verzeichnis auflisten, deren Name diese Job-ID beinhaltet... nix leichter als das:

--14.09.2011 hubionmac.com

-- parts of numbers selection code by http://hints.macworld.com/article.php?story=20090109055630154

-- requested @https://discussions.apple.com/thread/3325583?tstart=0

-- this script takes the value of a selection in numbers first and a asks for a folder

-- then the values of the first column of the selection are taken and all filenames of start start with that folder and are found in the defined folder will be

-- writen to the last column of the selection ----> you will have to select at least 2 columns


set thefolder to quoted form of POSIX path of ((choose folder) as alias)


tell application "Numbers"

activate

tell document 1

-- DETERMINE THE CURRENT SHEET

set current_sheet_index to 0

repeat with i from 1 to the count of sheets

tell sheet i

set x to the count of (tables whose selection range is not missing value)

end tell

if x is not 0 then

set the current_sheet_index to i

exit repeat

end if

end repeat

if the current_sheet_index is 0 then error "No sheet has a selected table."

-- GET THE VALUES OF THE SELECTED CELLS

tell sheet current_sheet_index

set the current_table to the first table whose selection range is not missing value

tell the current_table

set range_column_count to count of every column of selection range

set this_rows_first_cell_index to 1

set this_rows_last_cell_index to range_column_count

-- THIS CHANGES THE VALUE OF 

repeat with i from 2 to count of every cell of selection range

set thename to value of cell this_rows_first_cell_index of selection range

set foundfilenames to my find_filenames(thefolder, thename)

set value of cell this_rows_last_cell_index of selection range to foundfilenames

set this_rows_first_cell_index to this_rows_first_cell_index + range_column_count

set this_rows_last_cell_index to this_rows_last_cell_index + range_column_count

if this_rows_last_cell_index > (count of every cell of selection range) then exit repeat

end repeat

end tell

end tell

end tell

end tell



on find_filenames(thefolder, filename_start)

-- THIS SEARCHES FILES STARTING WITH A SPECIFIC STRING IN THEIR NAMES AND OUTPUTS JUST THEIR FILENAMES

-- IS SEARCHES IN THEFOLDER AND ALL SUB-DIRECTORIES

set theoutput to do shell script "cd " & thefolder & ";find " & "." & " -iname \"" & filename_start & "*\""

if theoutput ≠ "" then

set theoutput to every paragraph of theoutput

--OPTIONAL REMOVE THE FIRST CHARACTER OF EACH PATH

set tmp to {}

repeat with t in theoutput

set tmp to tmp & {(characters 2 through -1 of t) as text}

end repeat

set theoutput to tmp

set AppleScript's text item delimiters to "; "

set theoutput to theoutput as text

set AppleScript's text item delimiters to ""

end if

return theoutput

end find_filenames

Posted in Numbers | Tagged , , | Leave a comment

Mein neues Keyboard ist da… und es ist sooo schön

Ich habe heute mein neues Keyboard (das vermeintlich beste Keyboard der Welt) ein "daskeyboard" bekommen. Und ich muss sagen,es tippt sich darauf mindestens so gut, wie auf meiner alten Erweitern Tastatur 2 von Apple, nur hat das Ding hier einen USB-Hub und keinen ADB-Anschluss mehr ;-) Manche dürfte das Tip-Geräusch nerven, aber es hört sich für mich fast wie Musik an und fühlt sich dabei so butterweich beim Tippen an.... =)!

@YouTube
Posted in Hardware | Tagged , , | Leave a comment
  • Seite übersetzen:


    Paypal for Pizza:




  • Kategorien


  • Letzte Kommentare

    • Niklas: Vielen Vielen Dank! So klappt es!
    • hubi: Servus Niklas, ich habe mir den Quellcode noch einmal angesehen und habe nun unter 10.7.3 einen Weg gefunden...
    • Niklas: Klingt super das Script. Leider bekomm ich immer folgende Fehlermeldung: error “„Mail“ hat einen Fehler...
    • Jürgen: Hallo Hubi, beim Abfragen von Kennworten gibt es noch eine böse Falle: Das Format, in dem security antwortet,...
    • hubi: Am einfachsten Du öffnest im AppleScript-Editor mal das Funktionsverzeichnis (unter Ablage) von iTunes. Ein...