Archive of articles classified as' "OS X"

Back home

OS X Lion: Fensterwiederherstellung für einzelne Programme sperren

11/08/2011
defaults write com.apple.QuickTimePlayerX NSQuitAlwaysKeepsWindows -bool false via OS X Lion: Fensterwiederherstellung für einzelne Programme sperren « macnews.de.In der Library, unter Saved Application State werden alle Programme aufgeführt, bei denen ein solcher SavedState bereits gespeichert wurde =) also warum nicht ein kleines Skript:

--11.08.2011 little script to edit saved state settings for a single app instead of all apps

global myhome

tell application "Finder"

set myhome to POSIX path of (home as alias)

set theitems to name of every item of folder "Saved Application State" of folder "Library" of home

set theapps to {}

repeat with theitem in theitems

if (theitem as text) ends with ".savedState" then

set theapps to theapps & ((characters 1 through -12 of theitem as text) as text)

end if

end repeat

end tell

set theapp to (choose from list theapps with prompt "Which app with saved state?") as text

set theactions to {"Delete SavedState", "Disable SavedState", "Enable SavedState", "Freeze Saved State", "Defrost Saved State"}

set theaction to (choose from list theactions with prompt "Which action?") as text

if theaction = (item 1 of theactions) as text then

my deleteSavedState(theapp)

else if theaction as text = (item 2 of theactions) as text then

my disableSavedState(theapp)

else if theaction as text = (item 3 of theactions) as text then

my enableSavedState(theapp)

else if theaction as text = (item 4 of theactions) as text then

my freezeSavedState(theapp)

else if theaction as text = (item 5 of theactions) as text then

my defrostSavedState(theapp)

end if


on deleteSavedState(appName)

--moves avedState to user's trash folder and plays drag to trash sound

do shell script "mv " & myhome & "Library/'Saved Application State'/" & quoted form of appName & ".savedState ~/.Trash/;afplay /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/dock/drag\\ to\\ trash.aif"

end deleteSavedState


on disableSavedState(appName)

--uses defaults write to disable saved state for this particular app

do shell script "defaults write " & appName & " NSQuitAlwaysKeepsWindows -bool false"

do shell script "afplay /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/ink/InkSoundBecomeMouse.aif"

end disableSavedState

on enableSavedState(appName)

--uses defaults write to disable saved state for this particular app

do shell script "defaults write " & appName & " NSQuitAlwaysKeepsWindows -bool true"

do shell script "afplay /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/ink/InkSoundBecomeMouse.aif"

end enableSavedState


on freezeSavedState(appName)

--changes user permissions to read only, so that savedStated is frozen

do shell script "chmod u-w " & myhome & "Library/'Saved Application State'/" & quoted form of appName & ".savedState"

do shell script "afplay /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/ink/InkSoundBecomeMouse.aif"

end freezeSavedState

on defrostSavedState(appName)

--changes user permissions to read&write again, so that savedStated is not frozen any more

do shell script "chmod u+w " & myhome & "Library/'Saved Application State'/" & quoted form of appName & ".savedState"

do shell script "afplay /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/ink/InkSoundBecomeMouse.aif"

end defrostSavedState

Update:

Ok, das hier ist nun wirklich eine schönere Lösung: http://www.tuaw.com/2011/07/26/dear-aunt-tuaw-help-me-fine-tune-session-window-restores/
No Comments

Wie lange braucht mein Mac zum Aufwachen…

7/05/2011
Ich finde es etwas fragwürdig, das per Skript zu messen... aber wie sonst? Es ist aber ein nettes Beispiel, wie man pmset skripten kann.

--07.05.2011 hubionmac.com

--skript that measures the time until wakeup is complete

-- this gives a f*** about your wakeorpoweron settings, they will be deleted!!!


set mystartup to build_pmset_date(1)

set ct to current date

tell application "Finder" to sleep

repeat until 1 = 0

if ct > mystartup then

exit repeat

else

set ct to current date

delay 1

end if

end repeat

set diff to ct - mystartup

display dialog "Waking up took me " & diff & " sec."

--clean wakup-plan

do shell script "pmset repeat cancel" with administrator privileges



on build_pmset_date(plusminutes)

set d to (current date) + (plusminutes * 60)

--make sure that we will end up with at least 1 minute...

if seconds of d > 30 then

set d to d + 60

end if

set thehour to characters -2 through -1 of (("0" & (hours of d as integer)) as text)

set theminutes to characters -2 through -1 of (("0" & (minutes of d as integer)) as text)

--pmset does not care about seconds...

set theseconds to "00"

set seconds of d to 0

set thetime to thehour & ":" & theminutes & ":" & theseconds

--clean wakup-plan

do shell script "pmset repeat cancel" with administrator privileges

--set the plan

do shell script "pmset repeat wakeorpoweron MTWRFSU \"" & thetime & "\"" with administrator privileges

return d

end build_pmset_date

No Comments

GUI Scripting: Sondertasten umstellen…

25/03/2011
Ich habe immer noch nicht viel für GUI-Scripting übrig, aber wie sonst könnte man die Sondertasten per Skript umstellen?

-- hubionmac.com 24.03.2011 (tested with 10.6.7)


tell application "System Preferences"

activate

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

tell application "System Events"

tell process "System Preferences"

click button 1 of tab group 1 of window 1

set curOpt to (get value of pop up button 3 of sheet 1 of window 1)

set curCmd to (get value of pop up button 4 of sheet 1 of window 1)

click pop up button 4 of sheet 1 of window 1

my set_button_item(1)

click pop up button 3 of sheet 1 of window 1

my set_button_item(2)

click pop up button 2 of sheet 1 of window 1

my set_button_item(3)

click pop up button 1 of sheet 1 of window 1

my set_button_item(4)

delay 0.25

keystroke return

end tell

end tell

quit

end tell


on set_button_item(valueindex)

tell application "System Events"

tell process "System Preferences"

repeat with i from 1 to 5

key code 126

delay 0.25

end repeat

repeat with i from 1 to valueindex - 1

key code 125

delay 0.25

end repeat

keystroke return

end tell

end tell

end set_button_item

No Comments

Terror Skript aus meinen Anfängen

8/03/2011
Ich habe das mal zum Spaß als App gespeichert, mit dem Photo Booth-Icon versehen und im Dock abgelegt... Ein Klick und schon war alles weg... Bitte also vor dem Ausführen des Skripts ungesicherte Dateien speichern, da sämtliche aktiven Programme im Dock (inkl. Finder) gekillt werden (-9 )!

-- 07.03.2006 hubionmac.com

tell application "System Events"

set myids to {}

set allApps to every application process whose background only is false

repeat with j in allApps

--if name of j is not "Finder" then

set myids to myids & unix id of j

--- end if

end repeat

end tell

set AppleScript's text item delimiters to " "

set myids to myids as text

set AppleScript's text item delimiters to ""

do shell script "kill -9 " & myids

No Comments

AppleScript: Computer sperren mit Anmeldefenster

23/10/2010
Neben der Passwort-Abfrage über den Bildschirmschoner wäre es doch auch schön, wie unter Windows einfach ein normales Anmeldefenster zu sehen. Der eigene Benutzer bleibt also angemeldet, seine Programme laufen weiter, aber anderen Nutzern wird auch die Möglichkeit gegegeben sich selber anzumelden. Unter Windows erreicht ich das mit windows-Taste + L auf dem Mac u.a. mit einem AppleScript-Aufruf, den ich mir via FastScripts auf einen entsprechenden Short-Cut gelegt habe.
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

do shell script "/System/Library/CoreServices/'Menu Extras'/User.menu/Contents/Resources/CGSession -suspend"

4 Comments

Batterielaufzeit messen

24/08/2010

Wenn man mal wissen möchte, wie lange die Batterie läuft und wie der Ladungsverlauf so aussieht, kann man sich mit pmset -g pslog >> ~/Desktop/pslog.txt ein Log schreiben lassen...


No Comments

.webloc vs .url -> Weburl Verweise

12/06/2010
Laut diesem Thread bei Stack Overflow kann man .webloc Dateien neben der Variante Drag&Drop auch von Hand schreiben und zwar im XML-Format seit Mac OS 10.3. Eine besonders kurze und wohl auch universellere Variante ist das .url Format:
Code zum markieren einmal anklicken

[InternetShortcut]

URL=http://www.apple.com/

 

Wichtig dabei ist dass, die Datei auf 3 Zeilen besteht, also die letzte leer ist.
1 Comment

AppleScript: Monitore synchronisieren aktivieren per Skript

19/03/2010
Ist zwar übelstes GUI-Skripting, mag aber dem ein oder anderen helfen...
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

do shell script "open /System/Library/PreferencePanes/Displays.prefPane"

delay 2 --wenn Dein Rechner da langsamer ist... größerer Delay... I love GUI-Scripting

activate application "System Preferences"

tell application "System Events"

tell process "System Preferences"

if title of radio button 2 of tab group 1 of window 1 = "Anordnen" then

click radio button "Anordnen" of tab group 1 of window 1

click checkbox 1 of group 1 of tab group 1 of window 1

else

display dialog "Falsche Sprache oder kein 2. Monitor"

end if

end tell

end tell

tell application "System Preferences" to quit

Übrigens ein geniales Tool für GUI-Skripting ist der UI-Browser, wenngleich ich die 55$ für ein solches Tool einfach nur überzogen finde!
No Comments

Applescript: Bildschirmfoto alle 30 Sekunden (nur das Geräusch verrät einen ;-))

25/02/2010
Das hier als AppleScript-File abspeichern
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

set dFolder to "~/Desktop/screencapture/"


do shell script ("mkdir -p " & dFolder)


repeat 2 times

set dateTime to do shell script "date +%Y%m%d_%H%M%S"

do shell script ("screencapture " & dFolder & dateTime & ".png") -- Capture screen.

delay 2 -- Wait for 30 seconds.

end repeat

und crontab ablaufen lassen... z.B. 40 8 * * * osascript /Users/hubi/scripts/screenshooter.scpt Ach, wie sinnlos praktisch =)
No Comments

Exposé mit AppleScript steuern

25/02/2010
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

do shell script "/Applications/Utilities/Expose.app/Contents/MacOS/Expose 1"

...wobei natürlich die 1 auch eine 2, 3 oder sonst etwas sein kann (Quelle).
No Comments