2 votos

Applescript: guardar en PDF todas las pestañas abiertas en Chrome

Me gustaría hacer un AppleScript que guarde en un PDF todas las pestañas abiertas en la ventana frontal en Google Chrome.

Aquí está mi MWE de trabajo hasta el momento:

tell application "Google Chrome"
    set allTabs to tabs in front window
    repeat with myTab in allTabs
        tell myTab to print
    end repeat
end tell

Por supuesto, esto simplemente abre la ventana de impresión repetidamente para cada pestaña abierta.

Idealmente, podría guardar cada uno en un PDF distinto, algo como esto (usando algunos comandos inventados aquí):

tell application "Google Chrome"
    set myFolder to "/Users/nnn/Desktop/PDF/"
    set myCount to 0
    repeat with myTab in allTabs
        set myCount to myCount + 1
        set fileName to "pdf" & myCount & ".pdf"
        set outputPath to myFolder & fileName
        export myTab to outputPath as PDF  -- obviously, this does not work.
    end repeat
end tell

¿Cómo puedo hacer que funcione?

1 votos

¿Puede utilizar una url a pdf api?

0 votos

@JBis, no tengo ningún problema con eso, pero las páginas web en cuestión requieren un inicio de sesión en Amazon, por lo que una aplicación que sólo haga una descarga por lotes de URLs probablemente no funcionará.

1 votos

Todo lo que veo en Internet es el uso de los menús contextuales y los clics para hacer las cosas. No me gusta / no sé cómo hacer esas cosas. Si encuentro una manera de hacerlo sin eso. Entonces voy a tratar de ayudar. Buena suerte.

1voto

George Puntos 112

He encontrado una solución, utilizando secuencias de comandos de interfaz de usuario, que hace lo que necesito:

tell application "Google Chrome"
    set myWindow to front window
    set myTabs to tabs in myWindow

    set outputFolder to "/Users/nnn/Desktop/PDF/"
    set myCount to 0

    activate

    repeat with myTab in myTabs
        set myCount to myCount + 1
        set fileName to "pdf" & myCount & ".pdf"
        set outputPath to outputFolder & fileName

        --N.B.: the following opens the system print window, not Google Chrome’s
        tell myTab to print

        tell application "System Events"
            tell process "Google Chrome"
                repeat until window "Print" exists
                    delay 0.02
                end repeat

                set printWindow to window "Print"

                tell printWindow
                    set myButton to menu button "PDF"
                    click myButton

                    repeat until exists menu 1 of myButton
                        delay 0.02
                    end repeat

                    set myMenu to menu 1 of myButton
                    set myMenuItem to menu item "Save as PDF" of myMenu
                    click myMenuItem

                    repeat until exists sheet 1
                        delay 0.02
                    end repeat

                    set saveSheet to sheet 1
                    tell saveSheet
                        set value of first text field to fileName
                        keystroke "g" using {command down, shift down}

                        repeat until exists sheet 1 of saveSheet
                            delay 0.02
                        end repeat

                        set goDialogue to sheet 1 of saveSheet

                        tell goDialogue
                            set value of first combo box to outputFolder
                            click button "Go"
                        end tell

                        click button "Save"
                    end tell
                end tell

                repeat while printWindow exists
                    delay 0.02
                end repeat
            end tell
        end tell
    end repeat
end tell

0 votos

¿Guardará pdfs para CADA ficha? ¿O sólo las que contengan archivos PDF?

AppleAyuda.com

AppleAyuda es una comunidad de usuarios de los productos de Apple en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X