Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
拆分字符串并获取AppleScript中的第一个元素_Applescript - Fatal编程技术网

拆分字符串并获取AppleScript中的第一个元素

拆分字符串并获取AppleScript中的第一个元素,applescript,Applescript,我想要一个具有以下功能的AppleScript: 给定一个字符串(Kdiff\u full\u call)作为参数 拆开一根线,然后 第一个元素,是zip文件的路径 解压下载目录中的文件 我如何在AppleScript中做到这一点 Kdiff_full_调用具有以下模式:string1-string2-string3-string4 到目前为止,我有以下脚本: on open location kdiff_full_call set array to my theSplit(kdif

我想要一个具有以下功能的AppleScript:

  • 给定一个字符串(
    Kdiff\u full\u call
    )作为参数
  • 拆开一根线,然后
  • 第一个元素,是zip文件的路径
  • 解压
    下载
    目录中的文件
我如何在AppleScript中做到这一点

Kdiff_full_调用
具有以下模式:string1-string2-string3-string4

到目前为止,我有以下脚本:

on open location kdiff_full_call
    set array to my theSplit(kdiff_full_call, "-")
    -- set string1 ... ??
do shell script "/usr/bin/unzip -d " & quoted form of string1
end open location

on theSplit(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 theSplit

你很接近。在中,作为数组的是项目列表。因此,您可以通过以下方式访问它:

set string1 to array's item 1
-- or
set string1 to item 1 of array
如果模式从未改变,并且字符串的数量始终相同,则更好

set {string1,string2,string3,string4} to array
我建议您根据VAR的内容重命名它们,以便更好地理解。我不选择string1,而是选择filePath(或其他)