AppleScript: descargar a una unidad AFP


1

Intento descargar archivos a una unidad AFP pero siempre tengo "Advertencia: no se pudo crear el archivo / Volumes / home / Downloads: Is a directory"

Pero el último comando funciona bien, dígale a la aplicación "Finder" que abra ("/ Volumes / home / Downloads" como archivo POSIX)

set theFileURL to the clipboard
set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
set theFile to text item -1 of theFileURL
set AppleScript's text item delimiters to TID

set theFilePath to "/Volumes/home/Downloads"
try
    do shell script "curl " & quoted form of theFileURL & " -o " & quoted form of POSIX path of theFilePath
    display dialog "The download is finished!" buttons {"OK"} default button 1 with icon note giving up after 5
on error theError
    display dialog "Error downloading the file:" & return & theFile & return & return & theError buttons {"OK"} default button 1 with icon 0 giving up after 5
end try


tell application "Finder" to open ("/Volumes/home/Downloads" as POSIX file)

en el mismo tipo de secuencia de comandos, también debo descargar torrent a mi Synology Download Station si alguien tiene una pista.

Respuestas:


1

El curl comando en el do shell script comando está mal formado. La -o opción espera un nombre de archivo o un nombre de archivo de ruta completo, no solo una ruta como la que theFilePath contiene la variable . Vea la página de manual para curl, en un tipo de Terminal, man curlpresione enter y luego desplácese hacia abajo hasta -o, --output <file>donde dice:Write output to <file> instead of stdout.

Entonces su do shell script comando debería verse así:

do shell script "curl " & quoted form of theFileURL & " -o " & quoted form of POSIX path of (theFilePath & "/" & theFile)

Si incluye la /(barra) al final del valor que estableció para la theFilePath variable, por ejemplo set theFilePath to "/Volumes/home/Downloads/", puede eliminar & "/"del do shell script comando , que luego se vería así:

do shell script "curl " & quoted form of theFileURL & " -o " & quoted form of POSIX path of (theFilePath & theFile)

Además, como ya lo ha configurado theFilePath, puede usarlo en su tell application "Finder" declaración , por ejemplo:

tell application "Finder" to open theFilePath as POSIX file

Si desea que Finder active la apertura del archivo y, según cómo lo configure theFilePath(con o sin a /), use uno de los siguientes de manera apropiada:

tell application "Finder" to open (theFilePath & "/" & theFile) as POSIX file
tell application "Finder" to open (theFilePath & theFile) as POSIX file

El código AppleScript que se muestra a continuación contiene ambas formas de la theFilePath variable y el do shell script comando junto con dos versiones de la tell application "Finder" declaración con un conjunto comentado con el inicio --(doble guión).

set theFileURL to the clipboard
set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
set theFile to text item -1 of theFileURL
set AppleScript's text item delimiters to TID

-- set theFilePath to "/Volumes/home/Downloads"
set theFilePath to "/Volumes/home/Downloads/"

try
    -- do shell script "curl " & quoted form of theFileURL & " -o " & quoted form of POSIX path of (theFilePath & "/" & theFile)

    do shell script "curl " & quoted form of theFileURL & " -o " & quoted form of POSIX path of (theFilePath & theFile)

    display dialog "The download is finished!" buttons {"OK"} default button 1 with icon note giving up after 5
on error theError
    display dialog "Error downloading the file:" & return & theFile & return & return & theError buttons {"OK"} default button 1 with icon 0 giving up after 5
end try

tell application "Finder" to open theFilePath as POSIX file
-- tell application "Finder" to open (theFilePath & "/" & theFile) as POSIX file
-- tell application "Finder" to open (theFilePath & theFile) as POSIX file

@KevinCork, sentimos omití algunos paréntesis, en el do shell script comando , por lo que los agregó a theFilePath & theFile, y theFilePath & "/" & theFilepor ejemplo, (theFilePath & theFile)y (theFilePath & "/" & theFile)por lo que si la theFile variable de nombre de archivo tiene espacios se maneja adecuadamente.
— user3439894

por alguna razón solo está descargando los primeros bytes del archivo.
— Kevin

@KevinCork, ¿Puedes proporcionar la URL para que pueda probarla? Además, si lo usa curldirectamente en un Terminal, ¿descarga solo una parte del archivo?
— user3439894

claro, solo estoy probando con una URL aleatoria get.videolan.org/vlc/2.2.1/macosx/vlc-2.2.1.dmg
— Kevin

@KevinCork, ese archivo también me curlafecta tanto en AppleScript como en el uso de un terminal, por lo que no es un problema de AppleScript. Otros archivos me funcionan bien.
— user3439894
Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.