Space/Desktop mit Apple Script erstellen

M

maleeb

Registriert
Thread Starter
Dabei seit
25.02.2014
Beiträge
2
Reaktionspunkte
0
Hallo,
ist es möglich mit Applescript Spaces (Desktop) zu erstellen.
Ich habe überall gesucht jedoch echt nichts gefunden.

Immer wenn ich es ausführe soll ein Space erstellt werden.

Ich danke schonmal

grüße
 
Hi – mein spontan-naiver Ansatz mal als erster Vorschlag (erfordert ASObjC Runner):

Code:
[B]tell [/B][COLOR=#0433FF][FONT=Verdana][I]application[/I][/FONT][/COLOR][FONT=Verdana] "System Events" [/FONT][B]to [/B][COLOR=#0433FF][FONT=Verdana][B]key code[/B][/FONT][/COLOR][FONT=Verdana] 126 [/FONT][COLOR=#0433FF][FONT=Verdana]using [/FONT][/COLOR][COLOR=#812FDC][FONT=Verdana][I]control down 
[/I][/FONT][/COLOR][COLOR=#0433FF][FONT=Verdana][B]delay[/B][COLOR=#000000] 0.5[/COLOR][/FONT][/COLOR]
[B]tell [/B][COLOR=#0433FF][FONT=Verdana][I]application[/I][/FONT][/COLOR][FONT=Verdana] "ASObjC Runner" [/FONT][B]to [/B][COLOR=#0433FF][FONT=Verdana][B]click button [/B][/FONT][/COLOR][COLOR=#812FDC][FONT=Verdana][I]once [/I][/FONT][/COLOR][COLOR=#0433FF][FONT=Verdana]at[/FONT][/COLOR][FONT=Verdana] {([/FONT][B]first [/B][COLOR=#0433FF][FONT=Verdana][I]item [/I][/FONT][/COLOR][B]of[/B][FONT=Verdana] ([/FONT][B]get [/B][B]the [/B][COLOR=#812FDC][FONT=Verdana]dimensions [/FONT][/COLOR][B]of [/B][B]the [/B][B]first [/B][COLOR=#0433FF][FONT=Verdana][I]screen[/I][/FONT][/COLOR][FONT=Verdana])) - 20, 60}[/FONT]
 
Ohne ASOC:

Code:
[B]tell [/B][COLOR=#0433FF][FONT=Verdana][I]application[/I][/FONT][/COLOR][FONT=Verdana] "System Events"
[/FONT][COLOR=#5E6161][FONT=Verdana][COLOR=#000000]    [/COLOR]--mission control starten[/FONT][/COLOR]
[FONT=Verdana]    [COLOR=#012fbe][B]do shell script[/B][/COLOR] "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control"[/FONT]
[FONT=Verdana]    [B]tell[/B] [COLOR=#0433ff][I]process[/I][/COLOR] "Dock"[/FONT]
[FONT=Verdana]        [B]set[/B] [COLOR=#4f8f00]countSpaces[/COLOR] [B]to[/B] [COLOR=#0433ff][B]count[/B][/COLOR] [COLOR=#0433ff][I]buttons[/I][/COLOR] [B]of[/B] [COLOR=#0433ff][I]list[/I][/COLOR] 1 [B]of[/B] [COLOR=#0433ff][I]group[/I][/COLOR] 1[/FONT]
[COLOR=#5E6161][FONT=Verdana][COLOR=#000000]        [/COLOR]--neuer space[/FONT][/COLOR]
[COLOR=#0433FF][FONT=Verdana][COLOR=#000000]        [/COLOR][B]click [/B][I]button[/I][COLOR=#000000] 1 [B]of[/B] [/COLOR][I]group[/I][COLOR=#000000] 1[/COLOR][/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana][COLOR=#000000]        [/COLOR]--zum neuen space wechseln[/FONT][/COLOR]
[FONT=Verdana]        [B]repeat[/B] [B]until[/B] ([COLOR=#0433ff][B]count[/B][/COLOR] [COLOR=#0433ff][I]buttons[/I][/COLOR] [B]of[/B] [COLOR=#0433ff][I]list[/I][/COLOR] 1 [B]of[/B] [COLOR=#0433ff][I]group[/I][/COLOR] 1) = ([COLOR=#4f8f00]countSpaces[/COLOR] + 1)[/FONT]
[FONT=Verdana]        [B]end[/B] [B]repeat[/B][/FONT]
[FONT=Verdana]        [COLOR=#0433ff][B]click[/B][/COLOR] [COLOR=#0433ff][I]button[/I][/COLOR] ([COLOR=#4f8f00]countSpaces[/COLOR] + 1) [B]of[/B] [COLOR=#0433ff][I]list[/I][/COLOR] 1 [B]of[/B] [COLOR=#0433ff][I]group[/I][/COLOR] 1[/FONT]
[FONT=Verdana]    [B]end[/B] [B]tell[/B][/FONT]
[FONT=Verdana][B]end[/B] [B]tell[/B][/FONT]
 
  • Gefällt mir
Reaktionen: kermitd
ich danke euch beiden,
hat geklappt :)
 
Hab Pills schönes Skript noch in der Weise angepasst, dass, wenn Vollbild-Anwendungen ganz rechts in der Liste der Spaces geöffnet sind, trotzdem der neu erstellte Space korrekt ausgewählt wird (und den Stil dabei an meine Vorlieben angepasst :D ). Das Skript ist nun auch bei mir im Einsatz und per BTT mit der Fünf-Finger-Klick-Geste verbunden. :)

An Pill: Hast Du zufällig eine gute Idee, wie es möglich wäre, auch per Skript den aktuellen Space zu schließen? Insbesondere den aktuellen Space herauszukriegen, und (idealerweise) nicht auf das Erscheinen des x-Knopfes nach Verschieben der Cursorposition warten zu müssen? Bin jetzt ein wenig auf den Geschmack gekommen, das per Geste zu erledigen...
 
Das Schließen ist nicht das Problem, aber das Herausfinden des aktuellen Space ist hässlich. Prinzipiell kann man die com.apple.spaces.plist auslesen. Problem dabei ist nur, dass die plist nur bei einer Änderung durch das Dock geändert wird und nicht beim Wechseln des Space. In dem Vorschlag unten aktiviere und deaktiviere ich einfach ein Häkchen in den Einstellungen, das ist besser als jedes mal das Dock per killAll abzuschießen. Danach lässt sich dann die Plist auslesen.

Alternativ lässt sich das sicher auch mit ASOC machen, aber damit kennst du dich besser aus als ich.

Code:
[B]tell [/B][COLOR=#0433FF][FONT=Verdana][I]application[/I][/FONT][/COLOR][FONT=Verdana] "System Events"
[/FONT][COLOR=#5E6161][FONT=Verdana][COLOR=#000000]    [/COLOR]--updaten der com.apple.spaces.plist[/FONT][/COLOR]
[FONT=Verdana]    [B]tell[/B] [COLOR=#0433ff][I]application[/I][/COLOR] "System Preferences" [B]to[/B] [COLOR=#0433ff][B]reveal[/B][/COLOR] [COLOR=#0433ff][I]anchor[/I][/COLOR] "Spaces" [B]of[/B] [COLOR=#0433ff][I]pane[/I][/COLOR] [COLOR=#812fdc][I]id[/I][/COLOR] "com.apple.preference.expose"[/FONT]
[FONT=Verdana]    [B]tell[/B] [COLOR=#0433ff][I]process[/I][/COLOR] "System Preferences"[/FONT]
[FONT=Verdana]        [B]tell[/B] [COLOR=#0433ff][I]checkbox[/I][/COLOR] 1 [B]of[/B] [COLOR=#0433ff][I]group[/I][/COLOR] 2 [B]of[/B] [COLOR=#0433ff][I]window[/I][/COLOR] 1[/FONT]
[COLOR=#0433FF][FONT=Verdana][COLOR=#000000]            [/COLOR][B]click[/B][/FONT][/COLOR]
[COLOR=#0433FF][FONT=Verdana][COLOR=#000000]            [/COLOR][B]click[/B][/FONT][/COLOR]
[FONT=Verdana]        [B]end[/B] [B]tell[/B][/FONT]
[FONT=Verdana]    [B]end[/B] [B]tell[/B][/FONT]
[FONT=Verdana]    [B]tell[/B] [COLOR=#0433ff][I]application[/I][/COLOR] "System Preferences" [B]to[/B] [COLOR=#0433ff][B]quit[/B][/COLOR][/FONT]
[COLOR=#5E6161][FONT=Verdana][COLOR=#000000]    [/COLOR]--auslesen der com.apple.spaces.plist[/FONT][/COLOR]
[FONT=Verdana]    [B]set[/B] [COLOR=#4f8f00]allSpaceIDs[/COLOR] [B]to[/B] [B]every[/B] [COLOR=#0433ff][I]paragraph[/I][/COLOR] [B]of[/B] ([COLOR=#012fbe][B]do shell script[/B][/COLOR] "defaults read com.apple.spaces SpacesDisplayConfiguration|grep uuid|sed 's/[^A-Z0-9-]*//g'")[/FONT]
[FONT=Verdana]    [B]repeat[/B] [B]with[/B] [COLOR=#4f8f00]i[/COLOR] [B]from[/B] 2 [B]to[/B] [COLOR=#0433ff][B]count[/B][/COLOR] [COLOR=#4f8f00]allSpaceIDs[/COLOR][/FONT]
[FONT=Verdana]        [B]if[/B] [COLOR=#0433ff][I]item[/I][/COLOR] [COLOR=#4f8f00]i[/COLOR] [B]of[/B] [COLOR=#4f8f00]allSpaceIDs[/COLOR] = [COLOR=#0433ff][I]item[/I][/COLOR] 1 [B]of[/B] [COLOR=#4f8f00]allSpaceIDs[/COLOR] [B]then[/B][/FONT]
[FONT=Verdana]            [B]set[/B] [COLOR=#4f8f00]currentSpaceNo[/COLOR] [B]to[/B] [COLOR=#4f8f00]i[/COLOR] - 1[/FONT]
[FONT=Verdana]            [B]exit[/B] [B]repeat[/B][/FONT]
[FONT=Verdana]        [B]end[/B] [B]if[/B][/FONT]
[FONT=Verdana]    [B]end[/B] [B]repeat[/B][/FONT]
[COLOR=#5E6161][FONT=Verdana][COLOR=#000000]    [/COLOR]--Space schließen[/FONT][/COLOR]
[FONT=Verdana]    [B]tell[/B] [COLOR=#0433ff][I]process[/I][/COLOR] "Dock"[/FONT]
[FONT=Verdana]        [COLOR=#012fbe][B]do shell script[/B][/COLOR] "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control"[/FONT]
[FONT=Verdana]        [B]tell[/B] [COLOR=#0433ff][I]button[/I][/COLOR] ("Schreibtisch " & [COLOR=#4f8f00]currentSpaceNo[/COLOR]) [B]of[/B] [COLOR=#0433ff][I]list[/I][/COLOR] 1 [B]of[/B] [COLOR=#0433ff][I]group[/I][/COLOR] 1 [B]to[/B] [COLOR=#0433ff][B]perform[/B][/COLOR] [COLOR=#0433ff][I]action[/I][/COLOR] "AXRemoveDesktop"[/FONT]
[FONT=Verdana]    [B]end[/B] [B]tell[/B][/FONT]
[FONT=Verdana][B]end[/B] [B]tell[/B][/FONT]

Randbemerkung: Bei tell app "Mission Control" to launch hängt sich mein Skripteditor immer auf, daher nehme ich immer die do shell script Variante. Was da aber nun der Unterschied ist und warum das so ist, ist mir schleierhaft.
 
  • Gefällt mir
Reaktionen: kermitd
Super, vielen Dank! Ja, ist natürlich etwas unschön, aber, gut, solange es seinen Zweck erfüllt… :) Allein die Verzögerung für den Start der Systemeinstellungen ist mir zu lang. Aber dann lasse ich die jetzt einfach im Hintergrund laufen. Dann funktioniert das genau so wie ich mir das vorstelle. Verrückterweise scheint Apple keine Cocoa-API zu diesem Zweck bereitzustellen. Daher ist auch ASOC daußen. Beim Googlen stoße ich nur auf Lösungen, die Carbon benutzen (https://github.com/shabble/osx-space-id) . Selbst die Carbon-Lösungen nutzen aber private oder deprecated APIs die in 10.9 so nicht mehr zu funktionieren scheinen.

Ich hab das Ganze für meine Zwecke jetzt noch etwas erweitert:

- wenn ein Vollbild-Fenster im Vordergrund ist, wird der Vollbild-Modus beendet
- funktioniert unabhängig davon, ob Dashboard als Space angezeigt wird
- funktioniert auch, wenn die Systemeinstellungen auf einem anderen Space geöffnet sind
- schließt die Systemeinstellungen nicht nach Ausführung


Randbemerkung: Bei tell app "Mission Control" to launch hängt sich mein Skripteditor immer auf, daher nehme ich immer die do shell script Variante. Was da aber nun der Unterschied ist und warum das so ist, ist mir schleierhaft.

Das ist bei mir bloß bei activate und run der Fall, die beide ein Apple Event als Antwort erwarten. Könnte man natürlich dann auch ein “ignoring application responses…end” drumhängen
 
Zuletzt bearbeitet:
Hallo,

tolle Skripte!
Wenn man jetzt quasi das erste und letzte Skript verbindet, bräuchte man nicht den Weg über die Systemeinstellungen zu nehmen :)
Neuen Space erstellen+löschen (-> com.apple.spaces.plist wird aktualisiert)

Gruß
 
  • Gefällt mir
Reaktionen: Pill
Da hätte man auch selbst draufkommen können ;)

Code:
[FONT=Verdana][B]tell[/B] [COLOR=#0433ff][I]application[/I][/COLOR] "System Events"
[/FONT][FONT=Verdana]   [COLOR=#012fbe][B]do shell script[/B][/COLOR] "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control"[/FONT]
[FONT=Verdana]    [B]tell[/B] [COLOR=#0433ff][I]process[/I][/COLOR] "Dock"[/FONT]
[COLOR=#5E6161][FONT=Verdana]--updaten der com.apple.spaces.plist[/FONT][/COLOR]
[FONT=Verdana]        [B]set[/B] [COLOR=#4f8f00]countSpaces[/COLOR] [B]to[/B] [COLOR=#0433ff][B]count[/B][/COLOR] [COLOR=#0433ff][I]buttons[/I][/COLOR] [B]of[/B] [COLOR=#0433ff][I]list[/I][/COLOR] 1 [B]of[/B] [COLOR=#0433ff][I]group[/I][/COLOR] 1[/FONT]
[COLOR=#0433FF][FONT=Verdana][B]click [/B][I]button[/I][COLOR=#000000] 1 [B]of[/B] [/COLOR][I]group[/I][COLOR=#000000] 1[/COLOR][/FONT][/COLOR]
[FONT=Verdana]        [B]repeat[/B] [B]until[/B] ([COLOR=#0433ff][B]count[/B][/COLOR] [COLOR=#0433ff][I]buttons[/I][/COLOR] [B]of[/B] [COLOR=#0433ff][I]list[/I][/COLOR] 1 [B]of[/B] [COLOR=#0433ff][I]group[/I][/COLOR] 1) = ([COLOR=#4f8f00]countSpaces[/COLOR] + 1)[/FONT]
[FONT=Verdana]        [B]end[/B] [B]repeat[/B][/FONT]
[FONT=Verdana]        [B]tell[/B] [B]last[/B] [COLOR=#0433ff][I]button[/I][/COLOR] [B]of[/B] [COLOR=#0433ff][I]list[/I][/COLOR] 1 [B]of[/B] [COLOR=#0433ff][I]group[/I][/COLOR] 1 [B]to[/B] [COLOR=#0433ff][B]perform[/B][/COLOR] [COLOR=#0433ff][I]action[/I][/COLOR] "AXRemoveDesktop"[/FONT]
[COLOR=#5E6161][FONT=Verdana]--auslesen der com.apple.spaces.plist[/FONT][/COLOR]
[FONT=Verdana]        [B]set[/B] [COLOR=#4f8f00]allSpaceIDs[/COLOR] [B]to[/B] [B]every[/B] [COLOR=#0433ff][I]paragraph[/I][/COLOR] [B]of[/B] ([COLOR=#012fbe][B]do shell script[/B][/COLOR] "defaults read com.apple.spaces SpacesDisplayConfiguration|grep uuid|sed 's/[^A-Z0-9-]*//g'")[/FONT]
[FONT=Verdana]        [B]repeat[/B] [B]with[/B] [COLOR=#4f8f00]i[/COLOR] [B]from[/B] 2 [B]to[/B] [COLOR=#0433ff][B]count[/B][/COLOR] [COLOR=#4f8f00]allSpaceIDs[/COLOR][/FONT]
[FONT=Verdana]            [B]if[/B] [COLOR=#0433ff][I]item[/I][/COLOR] [COLOR=#4f8f00]i[/COLOR] [B]of[/B] [COLOR=#4f8f00]allSpaceIDs[/COLOR] = [COLOR=#0433ff][I]item[/I][/COLOR] 1 [B]of[/B] [COLOR=#4f8f00]allSpaceIDs[/COLOR] [B]then[/B][/FONT]
[FONT=Verdana]                [B]set[/B] [COLOR=#4f8f00]currentSpaceNo[/COLOR] [B]to[/B] [COLOR=#4f8f00]i[/COLOR] - 1[/FONT]
[FONT=Verdana]                [B]exit[/B] [B]repeat[/B][/FONT]
[FONT=Verdana]            [B]end[/B] [B]if[/B][/FONT]
[FONT=Verdana]        [B]end[/B] [B]repeat[/B][/FONT]
[COLOR=#5E6161][FONT=Verdana]--Space schließen        [/FONT][/COLOR]
[FONT=Verdana]        [B]tell[/B] [COLOR=#0433ff][I]button[/I][/COLOR] ("Schreibtisch " & [COLOR=#4f8f00]currentSpaceNo[/COLOR]) [B]of[/B] [COLOR=#0433ff][I]list[/I][/COLOR] 1 [B]of[/B] [COLOR=#0433ff][I]group[/I][/COLOR] 1 [B]to[/B] [COLOR=#0433ff][B]perform[/B][/COLOR] [COLOR=#0433ff][I]action[/I][/COLOR] "AXRemoveDesktop"[/FONT]
[FONT=Verdana]    [B]end[/B] [B]tell[/B][/FONT]
[B]end [/B][B]tell
[/B]
 
Hallo,

da mich dieses Thema fasziniert, habe ich mir noch ein paar Gedanken gemacht und folgendes ist dabei herausgekommen.
Sollte mit allen Systemsprachen funktionieren und vor allem mit eigentlich jedem Programm, welches sich im Vollbild-Modus befindet.

Eine Sache gibt es aber, die ich im Augenblick nicht verstehe. Im Original-Skript steht
repeat with i from 2 to count allSpaceIDs

Das funktioniert auch bei meinem und einem weiteren (deutschsprachigen) Useraccount, nicht aber auf einem dritten (nicht deutschsprachigen) Account. Ich habe dort auch mal die Plist gelöscht (und zwar so, wie man es in Mavericks tun muss), was aber nichts änderte.
Ändere ich das auf
repeat with i from 3 to count allSpaceIDs
funktioniert das Skript auf allen Accounts:

Code:
[COLOR=#5730BE][FONT=Verdana][COLOR=#000000][B]set[/B] [/COLOR][COLOR=#4f8f00]|desktop|[/COLOR][COLOR=#000000] [B]to[/B] [/COLOR]displayed name[COLOR=#000000] [B]of[/B] ([/COLOR][COLOR=#012fbe][B]info for[/B][/COLOR][COLOR=#000000] ([/COLOR][COLOR=#012fbe][B]path to [/B][/COLOR][I]desktop[/I][COLOR=#000000]))[/COLOR][/FONT][/COLOR]
[FONT=Verdana]
[/FONT]
[FONT=Verdana][B]tell[/B] [COLOR=#0433ff][I]application[/I][/COLOR] "System Events"[/FONT]

[COLOR=#5E6161][FONT=Verdana]--exit full screen mode[/FONT][/COLOR]
[FONT=Verdana]    [B]set[/B] [COLOR=#4f8f00]frontmostProcess[/COLOR] [B]to[/B] [B]the[/B] [B]first[/B] [COLOR=#0433ff][I]process[/I][/COLOR] [B]whose[/B] [COLOR=#812fdc]frontmost[/COLOR] [B]is[/B] [COLOR=#812fdc][I]true[/I][/COLOR][/FONT]
[FONT=Verdana]    [B]try[/B][/FONT]
[FONT=Verdana]        [B]if[/B] [COLOR=#812fdc]position[/COLOR] [B]of[/B] [COLOR=#4f8f00]frontmostProcess's[/COLOR] [COLOR=#0433ff][I]window[/I][/COLOR] 1 [B]is[/B] {0, 0} [B]then[/B][/FONT]
[COLOR=#0433FF][FONT=Verdana][B]            key code[/B][COLOR=#000000] 53[/COLOR][/FONT][/COLOR]
[FONT=Verdana]            [COLOR=#0433ff][B]delay[/B][/COLOR] 2[/FONT]
[FONT=Verdana]        [B]end[/B] [B]if[/B][/FONT]
[FONT=Verdana]    [B]end[/B] [B]try[/B][/FONT]

[COLOR=#5E6161][FONT=Verdana]--Mission Control[/FONT][/COLOR]
[FONT=Verdana]    [B]tell[/B] [B]me[/B] [B]to[/B] [COLOR=#012fbe][B]do shell script[/B][/COLOR] "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control"[/FONT]
[FONT=Verdana]    [B]tell[/B] [COLOR=#0433ff][I]process[/I][/COLOR] "Dock"[/FONT]

[COLOR=#5E6161][FONT=Verdana]--com.apple.spaces.plist update[/FONT][/COLOR]
[FONT=Verdana]        [B]set[/B] [COLOR=#4f8f00]countSpaces[/COLOR] [B]to[/B] [COLOR=#0433ff][B]count[/B][/COLOR] [COLOR=#0433ff][I]buttons[/I][/COLOR] [B]of[/B] [B]the[/B] [B]first[/B] [COLOR=#0433ff][I]group's[/I][/COLOR] [B]first[/B] [COLOR=#0433ff][I]list[/I][/COLOR][/FONT]
[COLOR=#0433FF][FONT=Verdana][B]        click [/B][I]button[/I][COLOR=#000000] 1 [B]of[/B] [/COLOR][I]group[/I][COLOR=#000000] 1[/COLOR][/FONT][/COLOR]
[FONT=Verdana]        [B]repeat[/B] [B]until[/B] ([COLOR=#0433ff][B]count[/B][/COLOR] [COLOR=#0433ff][I]buttons[/I][/COLOR] [B]of[/B] [B]the[/B] [B]first[/B] [COLOR=#0433ff][I]group's[/I][/COLOR] [B]first[/B] [COLOR=#0433ff][I]list[/I][/COLOR]) = ([COLOR=#4f8f00]countSpaces[/COLOR] + 1)[/FONT]
[FONT=Verdana]        [B]end[/B] [B]repeat[/B][/FONT]
[FONT=Verdana]        [B]tell[/B] [B]last[/B] [COLOR=#0433ff][I]button[/I][/COLOR] [B]of[/B] [B]the[/B] [B]first[/B] [COLOR=#0433ff][I]group's[/I][/COLOR] [B]first[/B] [COLOR=#0433ff][I]list[/I][/COLOR] [B]to[/B] [COLOR=#0433ff][B]perform[/B][/COLOR] [COLOR=#0433ff][I]action[/I][/COLOR] "AXRemoveDesktop"[/FONT]

[COLOR=#5E6161][FONT=Verdana]--read com.apple.spaces.plist[/FONT][/COLOR]
[FONT=Verdana]        [B]tell[/B] [B]me[/B][/FONT]
[FONT=Verdana]            [B]set[/B] [COLOR=#4f8f00]dashboardEnabled[/COLOR] [B]to[/B] [COLOR=#012fbe][B]do shell script[/B][/COLOR] "defaults read com.apple.spaces SpacesDisplayConfiguration|grep -m1 dashboard|sed 's/.*/1/g'"[/FONT]
[FONT=Verdana]            [B]set[/B] [COLOR=#4f8f00]allSpaceIDs[/COLOR] [B]to[/B] [B]every[/B] [COLOR=#0433ff][I]paragraph[/I][/COLOR] [B]of[/B] ([COLOR=#012fbe][B]do shell script[/B][/COLOR] "defaults read com.apple.spaces SpacesDisplayConfiguration|grep uuid|sed 's/[^A-Z0-9-]*//g'")[/FONT]
[FONT=Verdana]            [B]repeat[/B] [B]with[/B] [COLOR=#4f8f00]i[/COLOR] [B]from[/B] 3 [B]to[/B] [COLOR=#0433ff][B]count[/B][/COLOR] [COLOR=#4f8f00]allSpaceIDs[/COLOR][/FONT]
[FONT=Verdana]                [B]if[/B] [COLOR=#0433ff][I]item[/I][/COLOR] [COLOR=#4f8f00]i[/COLOR] [B]of[/B] [COLOR=#4f8f00]allSpaceIDs[/COLOR] = [COLOR=#0433ff][I]item[/I][/COLOR] 1 [B]of[/B] [COLOR=#4f8f00]allSpaceIDs[/COLOR] [B]then[/B][/FONT]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]                    [B]set[/B] [/COLOR]currentSpaceNo[COLOR=#000000] [B]to[/B] [/COLOR]i[COLOR=#000000] - 1 - [/COLOR]dashboardEnabled[/FONT][/COLOR]
[FONT=Verdana]                    [B]exit[/B] [B]repeat[/B][/FONT]
[FONT=Verdana]                [B]end[/B] [B]if[/B][/FONT]
[FONT=Verdana]            [B]end[/B] [B]repeat[/B][/FONT]
[FONT=Verdana]        [B]end[/B] [B]tell[/B][/FONT]

[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]        [B]return[/B] [/COLOR]currentSpaceNo[/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]--close current Space        [/FONT][/COLOR]
[FONT=Verdana]        [B]tell[/B] ([COLOR=#0433ff][I]button[/I][/COLOR] ([COLOR=#4f8f00]|desktop|[/COLOR] & [COLOR=#812fdc]space[/COLOR] & [COLOR=#4f8f00]currentSpaceNo[/COLOR]) [B]of[/B] [B]the[/B] [B]first[/B] [COLOR=#0433ff][I]group's[/I][/COLOR] [B]first[/B] [COLOR=#0433ff][I]list[/I][/COLOR]) [B]to[/B] [COLOR=#0433ff][B]perform[/B][/COLOR] [COLOR=#0433ff][I]action[/I][/COLOR] "AXRemoveDesktop"[/FONT]
[FONT=Verdana]    [B]end[/B] [B]tell[/B][/FONT]

[COLOR=#5E6161][FONT=Verdana]--exit Mission Control[/FONT][/COLOR]
[FONT=Verdana]    [COLOR=#0433ff][B]delay[/B][/COLOR] 0.5[/FONT]
[COLOR=#0433FF][FONT=Verdana][B]    key code[/B][COLOR=#000000] 53[/COLOR][/FONT][/COLOR]

[FONT=Verdana][B]end[/B] [B]tell[/B][/FONT]
 
Zuletzt bearbeitet:
Ob das Dashboard aktiviert ist, könntest du so prüfen, dann sparst du dir den try-Block:


set dashboardEnabled to do shell script "defaults read com.apple.spaces SpacesDisplayConfiguration|grep -m1 dashboard|sed 's/.*/1/g'"


Theoretisch müsstest du von i = 2 + dashboardEnabled iterieren. Einen Zusammenhang mit der Sprache kann ich aber nicht erkennen. Du kannst ja mal schauen, ob sich die Ausgabe von

defaults read com.apple.spaces SpacesDisplayConfiguration|grep uuid|sed 's/[^A-Z0-9-]*//g'

unterscheidet.
 
Hallo

und danke für den Code! (wieder was gelernt!)

Und wenn wir schon beim Thema sind:
Hüstel ... :eek: ... was bedeutet iterieren?


Einen Zusammenhang mit der Sprache kann ich mittlerweile ausschließen.
Und ja, hmm, das hätte ich natürlich gleich erwähnen sollen, in wieweit die Plists sich unterscheiden (warum die Änderung im Skript nötig wurde)
In der com.apple.spaces.plist des dritten User-Accounts bekommt der letzte Space einfach keine UUID.

Naja ... ist wohl eher nicht normal :)


Gruß
 
Zuletzt bearbeitet:
Iterieren = schrittweise durchgehen (z.B. eine Schleife). Ich meine damit folgendes: Wenn das Dashboard aktiviert ist, dann muss e statt "repeat with i from 2 to..." "repeat with i from 3 to ..." heißen, denn dann gibt es ja 1 Space mehr.

Ich habe mal das Auslesen des aktuellen Spaces in einen Shell-Befehl zusammengefasst:

Code:
[COLOR=#000000][FONT=Verdana][B]set[/B] [/FONT][/COLOR][COLOR=#4F8F00][FONT=Verdana]|desktop|[/FONT][/COLOR][COLOR=#000000][FONT=Verdana] [B]to[/B] [/FONT][/COLOR][COLOR=#5730BE][FONT=Verdana]displayed name[/FONT][/COLOR][COLOR=#000000][FONT=Verdana] [B]of[/B] ([/FONT][/COLOR][COLOR=#012FBE][FONT=Verdana][B]info for[/B][/FONT][/COLOR][COLOR=#000000][FONT=Verdana] ([/FONT][/COLOR][COLOR=#012FBE][FONT=Verdana][B]path to [/B][/FONT][/COLOR][I]desktop[/I][COLOR=#000000][FONT=Verdana]))
[/FONT][/COLOR][FONT=Verdana][B]tell[/B] [COLOR=#0433ff][I]application[/I][/COLOR] "System Events"[/FONT]
[FONT=Verdana]    [/FONT]
[COLOR=#5E6161][FONT=Verdana][COLOR=#000000]    [/COLOR]--exit full screen mode[/FONT][/COLOR]
[FONT=Verdana]    [B]set[/B] [COLOR=#4f8f00]frontmostProcess[/COLOR] [B]to[/B] [B]the[/B] [B]first[/B] [COLOR=#0433ff][I]process[/I][/COLOR] [B]whose[/B] [COLOR=#812fdc]frontmost[/COLOR] [B]is[/B] [COLOR=#812fdc][I]true[/I][/COLOR][/FONT]
[FONT=Verdana]    [B]try[/B][/FONT]
[FONT=Verdana]        [B]if[/B] [COLOR=#812fdc]position[/COLOR] [B]of[/B] [COLOR=#4f8f00]frontmostProcess's[/COLOR] [COLOR=#0433ff][I]window[/I][/COLOR] 1 [B]is[/B] {0, 0} [B]then[/B][/FONT]
[COLOR=#0433FF][FONT=Verdana][COLOR=#000000]            [/COLOR][B]key code[/B][COLOR=#000000] 53[/COLOR][/FONT][/COLOR]
[FONT=Verdana]            [COLOR=#0433ff][B]delay[/B][/COLOR] 2[/FONT]
[FONT=Verdana]        [B]end[/B] [B]if[/B][/FONT]
[FONT=Verdana]    [B]end[/B] [B]try[/B][/FONT]
[COLOR=#942193][FONT=Menlo]    [/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana][COLOR=#000000]    [/COLOR]--Mission Control[/FONT][/COLOR]
[FONT=Verdana]    [B]tell[/B] [B]me[/B] [B]to[/B] [COLOR=#012fbe][B]do shell script[/B][/COLOR] "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control"[/FONT]
[FONT=Verdana]    [B]tell[/B] [COLOR=#0433ff][I]process[/I][/COLOR] "Dock"[/FONT]
[COLOR=#942193][FONT=Menlo]    [/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana][COLOR=#000000]        [/COLOR]--updaten der com.apple.spaces.plist[/FONT][/COLOR]
[FONT=Verdana]        [B]set[/B] [COLOR=#4f8f00]countSpaces[/COLOR] [B]to[/B] [COLOR=#0433ff][B]count[/B][/COLOR] [COLOR=#0433ff][I]buttons[/I][/COLOR] [B]of[/B] [B]the[/B] [B]first[/B] [COLOR=#0433ff][I]group's[/I][/COLOR] [B]first[/B] [COLOR=#0433ff][I]list[/I][/COLOR][/FONT]
[COLOR=#0433FF][FONT=Verdana][COLOR=#000000]        [/COLOR][B]click [/B][I]button[/I][COLOR=#000000] 1 [B]of[/B] [/COLOR][I]group[/I][COLOR=#000000] 1[/COLOR][/FONT][/COLOR]
[FONT=Verdana]        [B]repeat[/B] [B]until[/B] ([COLOR=#0433ff][B]count[/B][/COLOR] [COLOR=#0433ff][I]buttons[/I][/COLOR] [B]of[/B] [B]the[/B] [B]first[/B] [COLOR=#0433ff][I]group's[/I][/COLOR] [B]first[/B] [COLOR=#0433ff][I]list[/I][/COLOR]) = ([COLOR=#4f8f00]countSpaces[/COLOR] + 1)[/FONT]
[FONT=Verdana]        [B]end[/B] [B]repeat[/B][/FONT]
[FONT=Verdana]        [B]tell[/B] [B]last[/B] [COLOR=#0433ff][I]button[/I][/COLOR] [B]of[/B] [B]the[/B] [B]first[/B] [COLOR=#0433ff][I]group's[/I][/COLOR] [B]first[/B] [COLOR=#0433ff][I]list[/I][/COLOR] [B]to[/B] [COLOR=#0433ff][B]perform[/B][/COLOR] [COLOR=#0433ff][I]action[/I][/COLOR] "AXRemoveDesktop"[/FONT]
[COLOR=#942193][FONT=Menlo]        [/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana][COLOR=#000000]        [/COLOR]--read com.apple.spaces.plist[/FONT][/COLOR]
[FONT=Verdana]        [B]tell[/B] [B]me[/B] [B]to[/B] [B]set[/B] [COLOR=#4f8f00]currentSpaceNo[/COLOR] [B]to[/B] [COLOR=#012fbe][B]do shell script[/B][/COLOR] "IDs=$(defaults read com.apple.spaces SpacesDisplayConfiguration|grep uuid|sed 's/[^A-Z0-9-]*//g');[/FONT]
[FONT=Verdana]dash=$(defaults read com.apple.spaces SpacesDisplayConfiguration|grep -m1 dashboard|sed 's/.*/1/g');[/FONT]
[FONT=Verdana]echo \"$IDs\"|awk '/'$(echo \"$IDs\"|head -1)'/ && NR > 1{print NR - 1 - 0'$dash'}'"[/FONT]
[FONT=Verdana]
[/FONT]
[COLOR=#5E6161][FONT=Verdana][COLOR=#000000]        [/COLOR]--close current Space        [/FONT][/COLOR]
[FONT=Verdana]        [B]tell[/B] ([COLOR=#0433ff][I]button[/I][/COLOR] ([COLOR=#4f8f00]|desktop|[/COLOR] & [COLOR=#812fdc]space[/COLOR] & [COLOR=#4f8f00]currentSpaceNo[/COLOR]) [B]of[/B] [B]the[/B] [B]first[/B] [COLOR=#0433ff][I]group's[/I][/COLOR] [B]first[/B] [COLOR=#0433ff][I]list[/I][/COLOR]) [B]to[/B] [COLOR=#0433ff][B]perform[/B][/COLOR] [COLOR=#0433ff][I]action[/I][/COLOR] "AXRemoveDesktop"[/FONT]
[FONT=Verdana]    [B]end[/B] [B]tell[/B][/FONT]
[COLOR=#942193][FONT=Menlo]    [/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana][COLOR=#000000]    [/COLOR]--exit Mission Control[/FONT][/COLOR]
[FONT=Verdana]    [COLOR=#0433ff][B]delay[/B][/COLOR] 0.5[/FONT]
[COLOR=#0433FF][FONT=Verdana][COLOR=#000000]    [/COLOR][B]key code[/B][COLOR=#000000] 53[/COLOR][/FONT][/COLOR]
[B]end [/B][B]tell
[/B]
 
Danke für das Erklären :)

Gruß
 
Zurück
Oben Unten