Aktuelles Tastatur-Layout auslesen

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

This entry was posted in OS X and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

4 Comments

  1. Posted December 9, 2009 at 9:17 pm | Permalink

    Hallo,

    interessant - allumfassend funktionierend scheint es aber leider nicht zu sein.
    Gerade unter 10.6.2 getestet und erhalte den folgenden Fehler

    error "ls: /Users/fidel/Library/Preferences/ByHost/com.apple.HIToolbox.00000000-0000-1000-8000-0017F2040476.plist: No such file or directory" number 1

    Gruss
    fidel

  2. Hubi
    Posted December 9, 2009 at 9:35 pm | Permalink

    Hm, bei mir geht es... hast Du denn eine HIToolbox plist in dem Ordner?
    Schalte doch sonst mal eine weite Sprache im Tastaturlayout dazu... hm... oder habe ich das bei der Migration von 10.5 mitgenommen...?
    Bei mit läuft es nämlich unter 10.6.2

  3. Posted December 10, 2009 at 10:46 am | Permalink

    Also Zwischeninfo:
    Work-Mac mit 10.6.2 - hochgezogen von 10.5 -> Script funktionert.
    Egal ob eine oder mehrere Sprachen konfiguriert sind.

    Der Mac zuhause - siehe Kommentar 1 - ist komplett neu aufgesetzt - werde ich dann später mal gegenchecken wie die Lage dort aussieht bzgl plist.

    Gruss
    fidel

  4. Posted December 11, 2009 at 5:17 pm | Permalink

    Ok - es sieht so aus als ob auf meiner cleanen 10.6 Install nach einer falschen Datei innerhalb den Preferences gesucht wird.

    Screenshot:
    https://dl.getdropbox.com/u/223435/public_trash/20091211_161559_ss.jpg

    Hoffe die Info hilft dir weiter ;)

    Gruss
    fidel

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CAPTCHA:


5 + six =

Subscribe without commenting

  • 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...