Quiero usar osascript o alguna otra forma de automatizar "Restablecer el identificador de publicidad", ¿es posible?
Respuesta
¿Demasiados anuncios?Ejemplo #1 - a través de Google
Googleando he encontrado este hilo de Reddit titulado: quiero escribir de reajuste automático de secuencia de comandos para la Publicidad de Identificador.
La secuencia de comandos desde una de las respuestas en que el hilo está por debajo.
NOTA: yo no prueba esto, simplemente estoy compartiendo como algo que puede ayudar a orientar en la dirección correcta para, finalmente, lograr una solución viable para usted problema.
Para su INFORMACIÓN, he creado un pequeño script para esta. No es perfecto, y no funcionar de manera confiable en el fondo, pero por si ayuda a alguien:
-- TODO: make this run reliably in the background... set isRunning to false if application "System Preferences" is running then set isRunning to true tell application "System Preferences" activate reveal anchor "Privacy" of pane "com.apple.preference.security" end tell tell application "System Events" to tell process "System Preferences" delay 0.3 click button "Reset Advertising Identifier" of group 1 of tab group 1 of window "Security & Privacy" delay 0.2 click button "Reset identifier" of sheet 1 of window "Security & Privacy" end tell if isRunning is false then quit application "System Preferences" end if
Guión parece ser AppleScript.
Ejemplo #2 - he hecho uso de Automator
Este es el primer script que he hecho uso de Automator (tipo). He utilizado el botón de grabar y hacer clic a través de los pasos para crear un Flujo de trabajo.
Flujo De Trabajo De AutomatorUna vez me hizo flujo de trabajo puedo copiar/pegar en ScriptEditor.
Automator con los pasos Copy/Paste de Automator → ScriptEditorEn ScriptEditor podía haga clic en el botón de play para ejecutar la secuencia de comandos de debug y ver que funcionaba correctamente.
ScriptEditor Botón De PlayUno lo tenía funcionando razonablemente bien, yo las puse en una shell de Bash script para que pudiera funcionar independiente desde un terminal.
Y he aquí que el acabado de un script de Bash con el osascript
incrustado dentro de:
$ cat reset_advertisement_id.sh
#!/bin/bash
osascript <<HERE
-- Click the "Apple" menu.
delay 4.598414
set timeoutSeconds to 2.0
set uiScript to "click menu bar item \"Apple\" of menu bar 1 of application process \"Finder\""
my doWithTimeout(uiScript, timeoutSeconds)
-- System Preferences…
delay 1.185682
set timeoutSeconds to 2.0
set uiScript to "click menu item 4 of menu 1 of menu bar item \"Apple\" of menu bar 1 of application process \"Finder\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the "View" menu.
delay 4.124994
set timeoutSeconds to 2.0
set uiScript to "click menu bar item \"View\" of menu bar 1 of application process \"System Preferences\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Security & Privacy
delay 2.306638
set timeoutSeconds to 2.0
set uiScript to "click menu item \"Security & Privacy\" of menu 1 of menu bar item \"View\" of menu bar 1 of application process \"System Preferences\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the "Privacy" tab.
delay 4.31466
set timeoutSeconds to 2.0
set uiScript to "click radio button \"Privacy\" of tab group 1 of window \"Security & Privacy\" of application process \"System Preferences\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the text "Advertising"
delay 1.997132
set timeoutSeconds to 2.0
set uiScript to "click static text 1 of UI Element 1 of row 12 of table 1 of scroll area 1 of tab group 1 of window \"Security & Privacy\" of application process \"System Preferences\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the "Reset Advertising Identifier" button.
delay 1.234389
set timeoutSeconds to 2.0
set uiScript to "click UI Element \"Reset Advertising Identifier\" of group 1 of tab group 1 of window \"Security & Privacy\" of application process \"System Preferences\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the "Reset identifier" button.
delay 1.2831
set timeoutSeconds to 2.0
set uiScript to "click UI Element \"Reset identifier\" of sheet 1 of window \"Security & Privacy\" of application process \"System Preferences\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the "<fill in title>" button.
delay 1.436771
set timeoutSeconds to 2.0
set uiScript to "click UI Element 6 of window \"Security & Privacy\" of application process \"System Preferences\""
my doWithTimeout(uiScript, timeoutSeconds)
on doWithTimeout(uiScript, timeoutSeconds)
set endDate to (current date) + timeoutSeconds
repeat
try
run script "tell application \"System Events\"
" & uiScript & "
end tell"
exit repeat
on error errorMessage
if ((current date) > endDate) then
error "Can not " & uiScript
end if
end try
end repeat
end doWithTimeout
HERE
# REFS
# - https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/AutomatetheUserInterface.html
# - https://apple.stackexchange.com/questions/40944/a-programmatic-method-for-disabling-all-sharing-services
# - https://github.com/herrbischoff/awesome-macos-command-line
# - https://www.macobserver.com/tips/quick-tip/reset-mac-advertising-identifier/
# - https://scriptingosx.com/2018/08/user-interaction-from-bash-scripts/
# - https://www.macworld.com/article/1157370/applescriptsystempreferences.html
Para ejecutar esto:
$ ./reset_advertisement_id.sh