Benches macOS

9

applescript simple file download

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

hi, after a long long time of figuring out how to post a topic, i hope is not in the wrong spot.

i am simply trying to do a script that downloads a file from the internet.

(start applescript)

display dialog "Download url" default answer "" buttons {"Cancel", "Download"} default button 2

set x to text returned of the result

set p to "/Users/Sacalito/Downloads"

set the Downloads to p as file specification

set thisfileSRC to "x"

tell application "URL Access Scripting"

download file to Downloads replacing yes

end tell

(end applescript)

but i cant figure out how to also put an input text asking for the name of the file that will be saved, and it gives me and error ... Can’t make "/Users/Sacalito/Downloads/" into type file specification.

so i just want the window with the input for the URL

and the input for the name of the file

the download directory is on downloads folder

and the download button to download file

9 replies

Sign in or join Beachball Help to reply.

  1. 0

    Niel

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Use a construct such as:

    display dialog "Download url" default answer "" buttons {"Cancel", "Download"} default button 2

    set x to text returned of the result

    set p to "Macintosh HD:Users:Sacalito:Downloads:Apple"

    tell application "URL Access Scripting"

    download x to file p replacing yes

    end tell

    (51244)

  2. 0

    red_menace

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    You can also use
    choose file name to set a name (and location) for the download, which can help in specifying the file correctly (AppleScript's
    file specification term is deprecated, the dictionary is just referring to something that specifies a file). In the following example, I increased the size of the URL text input field and extracted the original name and extension from the URL for use in the
    choose file name dialog:

    <pre style="

    font-family: Monaco, 'Courier New', Courier, monospace;

    font-size: 10px;

    font-weight: normal;

    margin: 0px;

    padding: 5px;

    border: 1px solid #000000;

    width: 720px;

    color: #000000;

    background-color: #DAFFB6;

    overflow: auto;"

    title="this text can be pasted into the Script Editor">

    display dialog "Download URL" default answer (return & return) buttons {"Cancel", "Download"} default button 2

    set theURL to text returned of the result

    set theName to text -((offset of "/" in (reverse of characters of theURL) as text) - 1) thru -1 of theURL

    set theFile to (choose file name default name theName default location (path to downloads folder))

    tell application "URL Access Scripting" to download theURL to theFile replacing yes

    </pre>

    *URL Access Scripting* seems to be a bit finicky though, so an alternative would be to use the
    curl shell script. To use this, just replace the entire
    tell statement with:

    <pre style="

    font-family: Monaco, 'Courier New', Courier, monospace;

    font-size: 10px;

    font-weight: normal;

    margin: 0px;

    padding: 5px;

    border: 1px solid #000000;

    width: 720px;

    color: #000000;

    background-color: #DAFFB6;

    overflow: auto;"

    title="this text can be pasted into the Script Editor">

    do shell script "/usr/bin/curl " & theURL & " -o " & quoted form of POSIX path of theFile

    </pre>

    There is also a separate AppleScript forum, it is located
    here.

  3. 0

    Niel

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Use a construct such as:

    display dialog "Download url" default answer "" buttons {"Cancel", "Download"} default button 2

    set x to text returned of the result

    set p to "Macintosh HD:Users:Sacalito:Downloads:Apple"

    tell application "URL Access Scripting"

    download x to file p replacing yes

    end tell

    (51244)

  4. 0

    sacalito

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    thanks for the help

    but i still get an error

    URL Access Scripting got an error: Unsupported scheme

  5. 0

    sacalito

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    the exact error is this one

    error "Can’t make "/Users/Sacalito/Downloads/" into type file specification." number -1700 from "/Users/Sacalito/Downloads/" to file specification

    thanks

  6. 0

    sacalito

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    ok i figured it out, but i am still missing how to put the input text for the name

    i cant get to put a variable that was set to text returned of a input text in the name secction

    display dialog "Download url" default answer "" buttons {"Cancel", "Download"} default button 2

    set x to text returned of the result

    display dialog "Name" default answer "" buttons {"Cancel", "OK"} default button 2

    set n to text returned of the result

    set p to ("/Users/Sacalito/Downloads/" & "n")

    tell application "URL Access Scripting"

    download x to file p replacing yes

    end tell

  7. 0

    Niel

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Here:

    display dialog "Download url" default answer "" buttons {"Cancel", "Download"} default button 2

    set x to text returned of the result

    display dialog "Name" default answer "" buttons {"Cancel", "OK"} default button 2

    set n to text returned of the result

    set p to ("/Users/Sacalito/Downloads/" & n)

    tell application "URL Access Scripting"

    download x to file p replacing yes

    end tell

    (51249)

  8. 0

    red_menace

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    You can also use
    choose file name to set a name (and location) for the download, which can help in specifying the file correctly (AppleScript's
    file specification term is deprecated, the dictionary is just referring to something that specifies a file). In the following example, I increased the size of the URL text input field and extracted the original name and extension from the URL for use in the
    choose file name dialog:

    <pre style="

    font-family: Monaco, 'Courier New', Courier, monospace;

    font-size: 10px;

    font-weight: normal;

    margin: 0px;

    padding: 5px;

    border: 1px solid #000000;

    width: 720px;

    color: #000000;

    background-color: #DAFFB6;

    overflow: auto;"

    title="this text can be pasted into the Script Editor">

    display dialog "Download URL" default answer (return & return) buttons {"Cancel", "Download"} default button 2

    set theURL to text returned of the result

    set theName to text -((offset of "/" in (reverse of characters of theURL) as text) - 1) thru -1 of theURL

    set theFile to (choose file name default name theName default location (path to downloads folder))

    tell application "URL Access Scripting" to download theURL to theFile replacing yes

    </pre>

    *URL Access Scripting* seems to be a bit finicky though, so an alternative would be to use the
    curl shell script. To use this, just replace the entire
    tell statement with:

    <pre style="

    font-family: Monaco, 'Courier New', Courier, monospace;

    font-size: 10px;

    font-weight: normal;

    margin: 0px;

    padding: 5px;

    border: 1px solid #000000;

    width: 720px;

    color: #000000;

    background-color: #DAFFB6;

    overflow: auto;"

    title="this text can be pasted into the Script Editor">

    do shell script "/usr/bin/curl " & theURL & " -o " & quoted form of POSIX path of theFile

    </pre>

    There is also a separate AppleScript forum, it is located
    here.

  9. 0

    sacalito

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    niel thank you very much its been killing my head for few hours

    i really apreciate it

    thanks sacalito

    p.d. sorry about the wrong forum