Using the Macscript function to download and rename a file.

MoshiM

Active Member
Joined
Jan 31, 2018
Messages
439
Office Version
  1. 2016
Platform
  1. Windows
I couldn't get this sub to work so I've made some changes to it but I no longer have access to a MAC to test on. Can someone test this for me or tell me a way of downloading and renaming a file and then specifying its path while on MAC?


VBA Code:
Sub Testing_Procedure()

MAC_Download "https://www.cftc.gov/dea/newcot/deacom.txt", "MoshiM_CF.txt"

End Sub
Public Sub MAC_Download(URL As String, File_Name As String)

Dim Curl_2_Run As String', Downloads_Folder As String
 
'Const Folder_Path = "downloads folder"

'Downloads_Folder = MacScript("return (path to " & Folder_Path & ") as string")
    
Curl_2_Run = "cd ~/Desktop; curl -o " & File_Name & " " & URL              '<--------Download and rename file..   save to desktop

MacScript Curl_2_Run

End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I've made some progress on this:

The actual script works in both the AppleScript editor and the Terminal, but I still can't get it to work through Excel. It gives me a "invalid procedure call or arguement" error.

VBA Code:
Sub CURL_TEST()

Dim CMD As String

CMD = "do shell script " & Chr(34) & "curl https://www.cftc.gov/dea/newcot/deacom.txt >~/Desktop/CFTC_Curl_Test.txt" & Chr(34)

MacScript CMD

'do shell script "curl https://www.cftc.gov/dea/newcot/deacom.txt >~/Desktop/CFTC_TEST.txt" <<<<<<<<< string that is typed into AppleScript editor

'curl https://www.cftc.gov/dea/newcot/deacom.txt >~/Desktop/CFTC_TEST.txt.                          <<<<<<<what is typed into the Terminal



End Sub
 
Upvote 0
I still don't have a solution for this one. Also note that I don't usually have access to a MAC to test on.
On a MAC the following line of code works properly to download and rename a file to the Downloads folder when ran from the Applescript editor
VBA Code:
do shell script "curl https://www.cftc.gov/dea/newcot/deacom.txt -o ~/Downloads/Test.txt"

I've converted it into a function so I can pass arguments to it:
Code:
On FileDownload(ShellCommand)

    do shell script ShellCommand

End FileDownload

And then called the .scpt file from Excel:

Code:
Sub Download_File_Mac(URL As String, Download As Boolean, Optional Unzip As Boolean) 'Download the file and send to Desktop

Dim Shell_Command As String, Return_STR As String

'Const URL As String = "https://www.cftc.gov/dea/newcot/deacom.txt"

#If Mac Then

    If Download Then
   
        If Val(Application.Version) >= 16 Then
       
            Shell_Command = "curl " & URL & " -o ~/Downloads/CFTC_Curl_Test.txt"
       
            Return_STR = AppleScriptTask("Execute_Curl.scpt", "FileDownload", Shell_Command)
       
        Else
       
            Shell_Command = "do shell script ""curl " & URL & ">~/Desktop/CFTC_Curl_Test.txt"""
           
            MacScript Shell_Command
           
        End If
   
    End If
   
    If Unzip Then
   
    End If
   
#End If

End Sub

However when I run the procedure , I'm prompted with "Invalid procedure call or argument (Error 5)" and no file is downloaded.

The .scpt file is in file path needed Run an AppleScript with VB

Additionally is ApplescriptTask even needed to execute curl statements or is Macscript sufficient for Excel 2016-19 ?

Are there other ways of doing this?
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top