How to call an applescript application from Office 2011 Excel VBA
I have been pounding my head how to implement a working VBA application into the Mac environment. I have tried a number of approaches calling applescript from VBA. I would like to call my applescript application and pass one argument. My applescript application is as follows:
<code>
on run argv
set theURL to (item 1 of argv)
set p_path to do shell script "echo ~"
set m_path to POSIX file p_path
set theName to text -((offset of "/" in (reverse of characters of theURL) as text) - 1) thru -1 of theURL
set theFile to (p_path & "/Downloads/" & theName)
set macPath to (POSIX file theFile)
do shell script "/usr/bin/curl " & theURL & " -o " & quoted form of POSIX path of macPath
end run
</code>
My last attempt within VBA is:
<code>
Sub SaveMetaDataFile(URL As String, shortFileName As String)
Dim scriptToRun As String
Dim posixcmd As String
posixcmd = ThisWorkbook.Path
scriptToRun = "tell application " & posixcmd & ":MetaDataFileDownloadScript.app " & URL
MsgBox "[" & scriptToRun & "]"
MacScript (scriptToRun)
</code>
I first tried to call the script directly without the "tell application" and I still obtain an error. I also tried the following in VBA and I get the same error with the last lane of code:
<code>
scriptToRun = "set theURL to " & """" & URL & """" & Chr(13)
scriptToRun = scriptToRun & "set p_path to do shell script " & """" & "/bin/echo ~ " & """" & Chr(13)
scriptToRun = scriptToRun & "set m_path to " & """" & posixcmd & """" & Chr(13)
scriptToRun = scriptToRun & "set theName to " & """" & shortFileName & """" & Chr(13)
scriptToRun = scriptToRun & "set theFile to (p_path & " & """/Downloads/""" & " & theName)" & Chr(13)
scriptToRun = scriptToRun & "set macPath to (POSIX file theFile)" & Chr(13)
scriptToRun = scriptToRun & "do shell script " & """" & "/usr/bin/curl " & """" & " & " & " theURL " & " & " & """" & " -o " & """" & " & " & " quoted form of POSIX path of macPath"
MsgBox scriptToRun
'scriptToRun = scriptToRun & "do shell script " & """/usr/bin/curl """ & " & " & " theURL " & """ -o """ & " & " & " quoted form of POSIX path of macPath"
MacScript (scriptToRun)
</code>
The above code is from the applescript application. The applescript application works well using the terminal via osascript. For example:
xenas-imac:Census Work Xena$ osascript MetaDataFileDownloadScript.app http://www2.census.gove/acs20095yr/summaryfile/Sequence_Number_and_Table_numberLookup.xls
xenas-imac:Census Work Xena$
The whole goal is to download a file into the Download directory from Excel to allow the next step to import the file into Excel for the user. Any help here would be great!
Thank you;
Lori
Mac OS X (10.6.5), iMac9,1; Intel Core 2 Duo 3.06 GHz