AppleScriptTask未将Result返回给VBA

时间:2017-03-15 02:47:22

标签: macos excel-vba applescript vba excel

当我使用AppleScriptTask调用Apple脚本的Mac Excel VBA宏时,我看到非常间歇性的返回结果。

我说断断续续,因为我可以以相同的方式运行相同的代码,有时我会得到我期望的结果,有时我得到一个空白的字符串。

当我使用以下行调用下面的GetPathInput函数时,我得到了我描述的间歇性行为:

customerDataDir = GetPathInput("Please select the directory you would like to use for Customer Data Output:" & userHomeDir & "Documents/Data/Customers/")

VBA Macro:

Function GetPathInput(ParameterStr As String) As String
Dim answer As Integer
answer = vbNo
Do Until answer = vbYes
    GetPathInput = AppleScriptTask("GetUserInput.scpt", "GetPathInput", ParameterStr)
    answer = MsgBox("Path: " & GetPathInput, vbYesNo, "Is this what you selected?")
Loop
End Function

AppleScript GetUserInput.scpt:

on GetPathInput(ParameterStr)
-- Takes 2 Parameters (Prompt for the Dialog, Default Path) 
set myParm to my splitParameters(ParameterStr, ":")
set PromptStr to item 1 of myParm
set DefaultPathStr to item 2 of myParm
return POSIX path of (choose folder with prompt PromptStr default location DefaultPathStr) as string
--  set DefaultPathStr to POSIX path of (path to home folder as string)
--  display dialog PathNameStr default answer DefaultPathStr
--  return text returned of result
end GetPathInput

AppleScript splitParameters:

on splitParameters(theString, theDelimiter)
-- save delimiters to restore old settings
set oldDelimiters to AppleScript's text item delimiters
-- set delimiters to delimiter to be used
set AppleScript's text item delimiters to theDelimiter
-- create the array
set theArray to every text item of theString
-- restore the old setting
set AppleScript's text item delimiters to oldDelimiters
-- return the result
return theArray
end splitParameters

0 个答案:

没有答案