iTunes Titelliste als Email veschicken

28 October, 2008 (23:31) | AppleScript Schnipsel, applescript | By: hubi

Ein kleines Skript (quick&dirty) um die Ausgewählten iTunes Titel (Name, Interpret und Album) als Liste via Email zu verschicken:

set thelist to ""

tell application "iTunes"

set h to selection of browser window 1

set i to 1

repeat with s in h

set thelist to thelist & i & ". " & name of s & " -- " & artist of s & " -- " & album of s & return

set i to i + 1

end repeat

end tell

tell application "Mail"

--close every window

set newMessage to make new outgoing message with properties {content:thelist as text}

tell newMessage

set visible to true

end tell

end tell

So ein Wacom Tablet kann schon Spaß machen…

15 October, 2008 (01:16) | filmchen, kreatives | By: hubi

...vor allen Dinge beim Abpausen

Mein erstes EyeTV Skript

9 October, 2008 (03:14) | AppleScript Schnipsel, EyeTV, applescript | By: hubi

Dieses Eye-TV Skript schaut nach, ob die in EyeTV ausgewählten Aufnahmen in ~/iTunes/iTunes Music/TV Shows bereits exportiert wurden (iPod m4v). Trifft dies zu, wird eine Zusammenfassung der Aufnahme als Textdatei in diesem Ordner erzeugt, die Exportierte Datei entsprechend
umbenannt und anschließend wird die Aufnahme aus Eye-TV GELÖSCHT. Ok den Part habe ich sicherheitshalber mal auskommentiert.So könnte man aber stumpf in EyeTV alle Aufnahmen auswählen, das Skript laufen lassen und das Skript "bereinigt" automatisch die Aufnahmeliste =)

tell application "EyeTV"

set these_r to selection of programs window

end tell

set thepath to do shell script "echo $HOME" & "/Music/iTunes/iTunes Music/TV Shows/"

repeat with this_r in these_r

tell application "EyeTV"

try

set this_year to (last word of (episode of this_r as text)) as integer

set theepisode to episode of this_r

on error

set this_year to 0

end try

set is_busy to busy of this_r

set the_contents to description of this_r as text

set the_name to (title of this_r) as text

set the_info to episode of this_r

end tell

try

set theepisode to replace_chars(theepisode, ":", "_")

set theepisode to replace_chars(theepisode, "/", "_")

end try

set the_name_ to replace_chars(the_name, ":", "_")

if is_busy = false then

if this_year is not 0 then

set the clipboard to the_name & " (" & this_year & ")" & return & return & the_info & return & return & the_contents as text

try

do shell script "mv " & quoted form of (thepath & the_name_ & "/" & theepisode & ".m4v") & " " & quoted form of thepath & quoted form of ("(" & this_year & ") ") & quoted form of the_name_ & ".m4v"

do shell script "pbpaste | cat>" & quoted form of thepath & quoted form of ("(" & this_year & ") ") & quoted form of the_name_ & ".txt"

(** tell application "EyeTV"

delete this_r

end tell**)

on error msg

--display dialog the_name_ & " gibt es anscheinend nicht."

end try

else

set the clipboard to the_name & return & return & the_info & return & return & the_contents as text

try

do shell script "mv " & quoted form of (thepath & the_name_ & "/" & theepisode & ".m4v") & " " & quoted form of thepath & quoted form of ("(" & this_year & ") ") & quoted form of the_name_ & ".m4v"

do shell script "pbpaste | cat>" & quoted form of thepath & quoted form of the_name_ & ".txt"

(** tell application "EyeTV"

delete this_r

end tell

**)

on error

--display dialog the_name_ & " gibt es anscheinend nicht."

end try

end if

end if

end repeat

on replace_chars(this_text, search_string, replacement_string)

if this_text contains the search_string then

set AppleScript's text item delimiters to the search_string

set the item_list to every text item of this_text

set AppleScript's text item delimiters to the replacement_string

set this_text to the item_list as string

set AppleScript's text item delimiters to ""

end if

return this_text

end replace_chars

Update

Die ist ein Beispiel, wie man die Original-EyTV-Aufnahme kopieren könnte...

tell application "EyeTV"

set these_r to selection of programs window

repeat with this_r in these_r

set this_location to location of this_r as text

set AppleScript's text item delimiters to ":"

set this_location to text items 1 through -2 of this_location as text

set AppleScript's text item delimiters to ""

set this_location to ((this_location & ":") as text) as alias

tell application "Finder"

activate

duplicate this_location to (choose folder)

end tell

end repeat

end tell

Aktuelles Tastatur via AppleScript Layout auslesen

6 October, 2008 (23:13) | AppleScript Schnipsel, applescript | By: hubi

Ich habe das Problem, dass das type4me blafasel-Skript aktuell nur richtig mit der deutschen und englischen Tastatur-Belegung funktioniert. Bei der Schweizer Tastatur, die der Französischen ähnlich ist, müsste ein andere Code ausgeführt werden, wenn Umlaute eingefügt werden sollen.
Deshalb suchte ich nach einem Weg die aktuelle Tastatur-Belegung (dt, en, fr usw.) via AppleScript auszulesen und das brachte mich dann über einige Tips auf diesen Seiten:

  1. http://bbs.macscripter.net/viewtopic.php?pid=70174
  2. http://www.afp548.com/article.php?story=leopard_byhost_changes
  3. http://www.jaharmi.com/2008/05/19/get_the_uuid_for_a_user_quickly_with_dsmemberutil_on_leopard
  4. http://www.afp548.com/article.php?story=leopard_byhost_changes

Tja, und hier das Resultat:

current_keyboard_layout()

on current_keyboard_layout()

set myversion to do shell script "sw_vers -productVersion"

if myversion "10.5.5" then

set pListPath to do shell script "ls ~/Library/Preferences/ByHost/com.apple.HIToolbox." & macs_UUID() & ".plist"

else

set pListPath to do shell script "ls ~/Library/Preferences/ByHost/com.apple.HIToolbox." & macs_MAC() & ".plist"

end if

tell application "System Events"

set pList to property list file pListPath

set a to property list items of property list item "AppleSelectedInputSources" of contents of pList

set theList to {}

set dialogText to "enabled keyboard layouts:" & return & return

repeat with i in a

set v to value of i

if |InputSourceKind| of v is "Keyboard Layout" then

set end of theList to v

return |KeyboardLayout Name| of v

end if

end repeat

end tell

end current_keyboard_layout

on macs_UUID()

set a to (do shell script "ioreg -rd1 -c IOPlatformExpertDevice | grep -E '(UUID)'")

set AppleScript's text item delimiters to "\""

set b to text item -2 of a

set AppleScript's text item delimiters to ""

return b

end macs_UUID

on macs_MAC()

set myMACaddress to (do shell script "ifconfig en0 ether | grep -i ether" as string) as string

set AppleScript's text item delimiters to " "

set b to every text item of myMACaddress

set AppleScript's text item delimiters to ""

repeat with k in b

if k contains ":" then

set AppleScript's text item delimiters to ":"

set myMAC to every text item of k

set AppleScript's text item delimiters to ""

return myMAC as text

exit repeat

end if

end repeat

end macs_MAC

Satan und ich fühlte mich als Kunde verarscht

5 October, 2008 (04:17) | Allgemein, NERV! | By: hubi

Anscheinend nicht nur ein begnadeter Programmiere und Tipper (die Antwort-Email kam nach knapp 1 1/2 Stunde), sonder auch noch rhetorisch ein Goldstück. Tja, wenn ich das alles schon vorher gewusst hätte,... Ich ziehe meinen Hut vor Dir, Mani und kann nun wieder ohne Bedenken jedem iVolume ans Herz legen :-)!
Read more »

Ordner via AppleScript synchronisieren über md5 Prüfsumme

5 October, 2008 (03:49) | AppleScript Schnipsel, applescript, entwicklung | By: hubi

Hatte mal wieder keine Lust ins Bett zu gehen und dabei ist dann das hier heraus gekommen:

(**

Installation:

   1. Wenn Du es das erste mal startest, erzeugt es einen Ordner mit dem Namen "SyncFolders_Script_aliases" auf deinem Start-Volumen und öffnet diesen.

   2. In diesen Ordner ziehst Du zunächst Aliase der Quell-Ordner (ja Du kannst mehrere Ordner in einen Zielordner synchronisieren).

   3. Diese Ordner-Alias bennenst Du um in SOURCE.. irgendwas, wichtig ist nur, dass SOURCE am Anfang steht

   4. Dann erstellst Du da noch einen Alias deines Zielordners, den Du DESTINATION irgendwas nennst

Dann nur noch starten und das Skript legt los =)

Wie es funktioniert?:

Die Dateien werden an Hand von md5 Prüfsummen unterschieden. Jede Dateien, deren md5-Prüfsumme mit denen der Dateien im Zielordner nicht übereinstimmt, wird umbenannt, nach dem Schema (+OUT<aktuelles Datum>) und dann kopiert. Sollte es beim Kopieren zu Problemen kommen, wird die Datei wieder "zurück-benannt" und das Skript läuft weiter. Am Ende erscheint in dem Fall aber eine Fehlermeldung.

In dem Skript Ordner wird zudem ein Datei log.txt geführt, in der dann bei jedem Start geschrieben wird, wie viel wohin kopiert wurde und ob es Fehler gegeben hat...

**)

set script_folder to "SyncFolders_Script_aliases"

set copycount to 0

set copiedpaths to ""

set errorpaths to ""

checkup(script_folder)

tell application "Finder"

set alias_folder to folder script_folder of startup disk

set source_aliases to (every alias file of alias_folder whose name starts with "SOURCE")

set destination_alias to (every alias file of alias_folder whose name starts with "DESTINATION")

end tell

set destination_files to md5_list(item 1 of destination_alias)

set source_files to {}

repeat with i from 1 to count of source_aliases

set source_files to source_files & md5_list(item i of source_aliases)

end repeat

-- assume that all sources are new sources

set newsources to source_files

repeat with destination_file in destination_files

set b to md5 of destination_file

repeat with source_file in source_files

if md5 of source_file = b then

--finally only new sources will stay in the newsources list 

set newsources to delete_from_list(source_file, newsources)

end if

end repeat

end repeat

set erroronmove to false

set prestring to "OUT+" & (do shell script "date +%Y%m%d")

repeat with newsource in newsources

set current_file to MacOSPath of newsource

tell application "Finder" to set current_file_name to (name of current_file)

--If the would be files already named "OUT+..:" that are NOT in the destination path 

--these would no be copied 

--if current_file_name does not start with "OUT+" then

set current_file to rename_file(current_file, prestring, current_file_name)

try

tell application "Finder"

set copiedfile to duplicate current_file to (original item of (item 1 of destination_alias)) as alias

set copycount to copycount + 1

set copiedpaths to copiedpaths & (POSIX path of (copiedfile as alias)<