Archive for category: AppleScript Schnipsel


Air-Tunes Speaker via Apple Skript switchen

18 December, 2008 (07:19) | AppleScript Schnipsel, applescript | By: hubi

-- ©hubionmac.com 18.12.2008

-- GUI-Skript mit dem die aktuelle Air-Tunes ausgabe verändert wird,

-- die aktuelle Airtunes-Lautsprecher-Auswahl werden quasi 

activate application "iTunes"

tell application "System Events"

get system attribute "sysv"

if result is greater than or equal to 4144 then -- Mac OS X 10.3.0

if UI elements enabled then

tell application process "iTunes"

if (name of button 15 of window "iTunes" as text) "" then

set noe to false

click button 15 of window "iTunes" --Den ITunes Lautsprecher Button drücken

delay 0.25

-- in der Liste ganz nach unten gehene (mehrere Lautsprecher auswählen Menüpunkt 

repeat with i from 1 to 5

key code 125

end repeat

keystroke return

try

repeat with i from 1 to (count of every UI element of window 1)

tell UI element i of window 1

set rowcount to count of rows

if rowcount > 0 then

if (value of checkbox 1 of row rowcount) as integer = 0 then

--dieser part beugt einer Fehlermeldung vor... 

--welcher? einfach mal diesen if-Block entfernen und Du wirst sehen =)

click checkbox 1 of row rowcount

set rowcount to rowcount - 1

end if

repeat with rownr from 1 to rowcount

click checkbox 1 of row rownr

end repeat

end if

end tell

end repeat

end try

keystroke "w" using command down

else

set noe to true

end if

end tell

else

beep

display dialog "GUI Scripting is not enabled" & return & return & "Open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane, then run this script again." with icon stop

if button returned of result is "OK" then

tell application "System Preferences"

activate

set current pane to pane "com.apple.preference.universalaccess"

end tell

end if

end if

else

beep

display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires an upgrade to Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit"

end if

end tell

if noe = true then

tell application "iTunes" to display dialog "nö, keine Airtunes Lautsprecher angeschlossen bzw. kein Button da, wo man so etwas auswählen könnt :-/"

end if


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


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()