Come si apre una nuova finestra in Safari e quindi si aprono più schede con diversi URL in quella finestra utilizzando lo script Apple?Come aprire una nuova finestra e più url in Safari con lo script Apple?
risposta
Il modo per creare una nuova finestra di Safari è quello di utilizzare il comando make new document
:
make new document at end of documents with properties {URL:the_url}
questo creerà una nuova finestra con una singola scheda che indica the_url
e fare quella finestra in primo piano. Si noti che make new window at end of windows
non funziona e si verificano solo errori con "Mancato funzionamento di AppleEvent".
Allo stesso modo, per creare una nuova scheda all'interno di una finestra w
, è possibile utilizzare make new tab
:
make new tab at end of tabs of w with properties {URL:the_url}
questo creerà una nuova scheda nella finestra di w
alla fine dell'elenco delle schede; questa scheda punterà a the_url
, e non sarà essere la scheda corrente. Invece di dire esplicitamente tabs of w
, è anche possibile utilizzare un blocco tell w
:
tell w
make new tab at end of tabs with properties {URL:the_url}
end tell
In questo modo, tabs
si riferisce implicitamente alla tabs of w
.
Mettendo tutto questo insieme, otteniamo il seguente script. Dato un elenco di URL in the_urls
, verrà aperto tutti in una nuova finestra; se the_urls
è vuoto, apre una finestra con una scheda vuota.
property the_urls : {¬
"http://stackoverflow.com", ¬
"http://tex.stackexchange.com", ¬
"http://apple.stackexchange.com"}
tell application "Safari"
if the_urls = {} then
-- If you don't want to open a new window for an empty list, replace the
-- following line with just "return"
set {first_url, rest_urls} to {"", {}}
else
-- `item 1 of ...` gets the first item of a list, `rest of ...` gets
-- everything after the first item of a list. We treat the two
-- differently because the first item must be placed in a new window, but
-- everything else must be placed in a new tab.
set {first_url, rest_urls} to {item 1 of the_urls, rest of the_urls}
end if
make new document at end of documents with properties {URL:first_url}
tell window 1
repeat with the_url in rest_urls
make new tab at end of tabs with properties {URL:the_url}
end repeat
end tell
end tell
tell application "Safari"
activate
set the URL of document 1 to "http://www.XXXXXXX.com"
my new_tab()
set the URL of document 1 to "http://www.XXXXXX.com"
end tell
on new_tab()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
«event prcsclic» «class menI» "New Tab" of «class menE» "File" of «class mbar» 1
end tell
end tell
end new_tab
Sostituire le X con qualsiasi sito che si desidera e continuare a ripetere il codice (il mio new_tab() e impostare l'URL ... righe) per ogni pagina che si desidera avere aperto. Riferimento a this page. Correggimi se questo non è quello di cui stavi parlando.
Grazie per la risposta, Pugmatt. È vicino a quello che voglio. Il tuo script apre l'url in una finestra di Safari esistente: voglio aprirlo in una nuova finestra. – sevens
Base sulla risposta di Pugmatt ho ottenuto il seguente al lavoro ...
on run {input, parameters}
tell application "Safari"
activate
make new document with properties {URL:"http://www.apple.com"}
my new_tab()
set the URL of document 1 to "http://www.example.com"
end tell
end run
on new_tab()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
«event prcsclic» «class menI» "New Tab" of «class menE» "File" of «class mbar» 1
end tell
end tell
end new_tab
Non sono sicuro se questo è il modo più efficiente di questo.
- 1. Aprire una nuova finestra in a4j: commandButton
- 2. Aprire una nuova finestra in MVVM
- 3. Stampa di una pagina Web usando solo url e senza aprire una nuova finestra?
- 4. jQuery function per aprire il collegamento in una nuova finestra
- 5. Come aprire un URL arbitrario in una nuova finestra con un pulsante primefaces
- 6. Aprire una nuova finestra dopo un evento click non funziona in Safari, Chrome
- 7. Rileva lo spostamento in una nuova scheda in Mobile Safari
- 8. Come aprire una nuova finestra in Windows Form in .NET?
- 9. Aprire la risposta su una nuova finestra
- 10. Apri URL nella nuova scheda Safari con AppleScript
- 11. Come aprire una nuova finestra e inserire HTML in esso utilizzando jQuery?
- 12. Android Phone: come aprire gli URL di dominio autorizzati in una nuova finestra del browser?
- 13. Come aprire una nuova scheda in CasperJS
- 14. Come faccio a creare un link per aprire URL esterni in una nuova finestra?
- 15. aprire una nuova finestra e chiamare la funzione javascript
- 16. Come aprire una nuova finestra sul modulo inviare
- 17. jQuery aprire una nuova finestra centrato con dimensione fissa
- 18. Come aprire una nuova finestra sulla modalità standalone di iPhone (a schermo intero)
- 19. Aprire un URL in una determinata scheda/finestra del browser
- 20. Crea una nuova discussione per aprire una nuova finestra e chiuderla da una discussione diversa
- 21. Come aprire una pagina in una nuova finestra o scheda da code-behind
- 22. Come posso aprire una nuova finestra usando jQuery?
- 23. Google CSE apre in una nuova finestra
- 24. Schema URL Apple Music
- 25. Lo script di shell avvia 1 sessione con più finestre
- 26. È possibile aprire una nuova finestra e incorporare iframe in questo?
- 27. Come posso passare le variabili GET URL di PHP per aprire una finestra con Javascript?
- 28. come aprire .pdf in una nuova scheda
- 29. Java Aprire una nuova finestra facendo clic su un pulsante
- 30. Come aprire una nuova applet da un'applet
grazie per la spiegazione aggiuntiva, Antal. Funziona! – sevens