从一个结果中获取多个变量(一个用于第一个字母,一个用于第二个字母,其余来自其余部分)

时间:2012-02-15 13:42:00

标签: macos scripting applescript

将一个变量从applescript中的对话框返回,这是非常简单的,但是是否可以将第一个和第二个字母用作两个单独的变量,其余的结果从对话框返回为第三个?下面是一个代码示例,其中包含我想要做的事情,以及我认为我想要做的事情。

    tell application "Finder"
        activate
        display dialog "newNameOfFolderDialogue" default answer "x"
            set categoryOne to [THE FIRST LETTER OF] (text returned of result)
            set categoryTwo to [THE SECOND LETTER OF] (text returned of result)
            set categoryThree to [THE REMAINING LETTERS OF] (text returned of result)
end tell

2 个答案:

答案 0 :(得分:0)

不能简单:

set theText to text returned of result
set categoryOne to the first character of theText
set categoryTwo to the second character of theText
set categoryThree to (text 3 thru (length of theText)) of theText

答案 1 :(得分:0)

甚至可以更简单:D包括检查用户的输入

set theText to text returned of (display dialog "newNameOfFolderDialogue" default answer "x")
if length of theText > 2 then --a safety check if the user has given the right answer
    tell theText to set {categoryOne, categoryTwo, categoryThree} to {character 1, character 2, text 3 thru -1}
else
    set {categoryOne, categoryTwo, categoryThree} to {null, null, null}
end if