Archive for tag: auslesen

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