Aktuelles Tastatur-Layout auslesen

6/12/2009
Ist an anscheinend ein mittlerer Akt unter OSX, so etwas auszulesen, da man die Prefs pro User & verwendeter Hardware unterschiedlich abgespeichert werden. Fundstück aus 2008.... habe ich glaube ich mal für type4meblafasel geschrieben....
Code zum markieren einmal anklicken

-- © hubionmac.com 7.10.2008

-- aktuelles keyboard layout ab OSX 10.5.5

-- Seit dieser Version hat Apple von mac-adresse auf uuid umgestellt (Preferences by Host und Time-Machine, glaube ich....

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

4 Comments

Aktuelles Tastatur via AppleScript Layout auslesen

6/10/2008
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:

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

No Comments