14 dicembre 2008

Abilitare/disabilitare il multi-window Mode in Safari

Per chi come me utilizza Mac Os X potrebbe essere davvero utile un appleScript mediante il quale poter abilitare e disabilitare l'apertura di nuove finestre di Safari.
Di default Safari, tende ad aprire i link in nuove Finestre anzichè utilizzare un nuovo Tab. Questo rende la navigazione alquanto caotica. Personalmente non ricordo se esista una voce nel menù di Safari per gestire questa particolare opzione.

Una soluzione è quella di crearsi uno script per poter scegliere la configurazione desiderata mediante una seplice Dialog.
Vediamo il codice:
beep
set choice to (display dialog ("Vuoi abilitare/disabilitare Safari in single window mode?") buttons {"Cancella", "Abilita", "Disabilita"} default button 1 with icon 1 with title "SSWM")

if the button returned of choice is not equal to "Cancellal" then
if the button returned of choice is equal to "Abilita" then
-- Terminal command to enable SWM
set cmd to ("defaults write com.apple.Safari TargetedClicksCreateTabs -bool true")
else
-- Terminal command to disable SWM
set cmd to ("defaults write com.apple.Safari TargetedClicksCreateTabs -bool false")
end if

try
-- Execute command
set x to (do shell script cmd)
-- Positive feedback
set x to (result & "Operazione eseguita!")
on error e
-- Return Error
set x to e
end try

-- Display feedback
if the button returned of choice is equal to "Abilita" or "Disabilita" then

set choice2 to (display dialog ((x as string) & return & "E' necessario riavviare Safari. Riavviare ora?") buttons {"Yes", "No"} default button 1 with icon 1 with title "SSWM")

-- Quit and restart Safari
if the button returned of choice2 is equal to "Yes" then
if application "Safari" is running then
tell application "Safari"
quit
end tell
delay 1
tell application "Safari"
activate
end tell
end if
end if
end if
end if

Il risultato ottenuto è la seguente finestrella :





Nessun commento: