Potrebbe esserci un modo più efficiente ma se si salva questo codice AppleScript in Script Editor, come applicazione, dopo averlo personalizzato in base alle proprie esigenze ... l'esecuzione di questa applicazione, come attualmente configurato, continuerà a essere eseguita e controllata ogni cinque secondi , fino a quando non viene rilevato un altro monitor.
property displayCount : 1
repeat until displayCount is greater than 1
tell application "Image Events"
set theDisplays to count of displays
end tell
set displayCount to theDisplays
delay 5 -- How Often To Check How Many Connected Monitors.. In Seconds
end repeat
-- The Following Line Will Execute When An Additional Display Is Connected
-- Replace The Following Code With Whatever Actions You Choose
activate
display dialog "New Display Connected" buttons {"Cancel", "OK"} default button "OK"
-- OR use the "run script" command as in the sample below
--set theScript to (path to desktop as text) & "whatever.scpt"
--set runScript to run script alias theScript
return
Questa opzione successiva rileva se un monitor è connesso o disconnesso e continuerà a funzionare
property displayCount : missing value
property tempDisplayCount : missing value
countDisplays()
repeat
repeat until displayCount is greater than 1
countDisplays()
end repeat
displayConnected()
countDisplays()
copy displayCount to tempDisplayCount
repeat until tempDisplayCount is not equal to displayCount
countDisplays()
end repeat
copy displayCount to tempDisplayCount
if tempDisplayCount is greater than displayCount then
displayConnected()
else if tempDisplayCount is equal to displayCount then
displayDisconnected()
end if
end repeat
on displayConnected()
-- The Following Lines Will Execute When An Additional Display Is Connected
-- Replace The Following Code With Whatever Actions You Choose
-- OR use the "run script" command as in the sample below
-- set theScript to (path to desktop as text) & "whatever.scpt"
-- set runScript to run script alias theScript
activate
set newDisplayConnected to button returned of (display dialog "New Display Connected" buttons {"Stop Monitoring", "Continue Monitoring"} default button "Continue Monitoring")
if newDisplayConnected is "Stop Monitoring" then
quit me
end if
end displayConnected
on displayDisconnected()
-- The Following Lines Will Execute When A Display Is Disconnected
-- Replace The Following Code With Whatever Actions You Choose
-- OR use the "run script" command as in the sample below
-- set theScript to (path to desktop as text) & "whatever.scpt"
-- set runScript to run script alias theScript
activate
set newDisplayDisconnected to button returned of (display dialog "A Display Was Disconnected" buttons {"Stop Monitoring", "Continue Monitoring"} default button "Continue Monitoring")
if newDisplayDisconnected is "Stop Monitoring" then
quit me
end if
end displayDisconnected
on countDisplays()
tell application "Image Events"
set theDisplays to count of displays
end tell
set displayCount to theDisplays
delay 5 -- How Often To Check How Many Connected Monitors.. In Seconds
end countDisplays