Puede haber una manera más eficiente, pero si guarda este siguiente AppleScript código en el Editor de secuencias de Comandos, como una aplicación, después de personalizar a sus necesidades... ejecutar esta aplicación, tal y como está configurado actualmente, seguirá funcionando y verificación de cada cinco segundos, hasta que un monitor adicional es detectado.
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
Este próximo opción de detectar si el monitor está conectado o desconectado y seguirá funcionando
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