curl Команда в do shell script команді має невірний формат. -o Варіант очікує ім'я файлу або повне ім'я шляху файлу не просто шлях , як то , що змінна theFilePath містить. Перегляньте довідкову сторінку для curlтипу Термінал man curlі натисніть клавішу Enter, а потім прокрутіть донизу, -o, --output <file>де зазначено:Write output to <file> instead of stdout.
Отже, ваша do shell script команда повинна виглядати так:
do shell script "curl " & quoted form of theFileURL & " -o " & quoted form of POSIX path of (theFilePath & "/" & theFile)
Якщо ви включите /(слэш) в кінці значення, яке ви встановили для theFilePath змінної, наприклад, set theFilePath to "/Volumes/home/Downloads/"ви можете усунути її & "/"з do shell script команди , яка б виглядала так:
do shell script "curl " & quoted form of theFileURL & " -o " & quoted form of POSIX path of (theFilePath & theFile)
Крім того, оскільки ви вже встановили, theFilePathви можете використовувати це у своїй tell application "Finder" заяві , наприклад:
tell application "Finder" to open theFilePath as POSIX file
Якщо ви хочете, щоб Finder ініціював відкриття файлу, і залежно від способу встановлення theFilePath(з а без нього /) використовуйте одне з наступних дій:
tell application "Finder" to open (theFilePath & "/" & theFile) as POSIX file
tell application "Finder" to open (theFilePath & theFile) as POSIX file
AppleScript код показаний нижче містить обидві форми theFilePath змінних і do shell script команду разом з двома версіями одного tell application "Finder" заяви з одним набором закоментувавши з провідним --(подвійним тиром).
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
do shell scriptкоманді , так що я додав їхtheFilePath & theFileі ,theFilePath & "/" & theFileнаприклад ,(theFilePath & theFile)і(theFilePath & "/" & theFile)тому , якщоtheFileзмінна ім'я файлу містить прогалини , воно належним чином.