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

发布于 2025-01-05 15:37:44 字数 529 浏览 3 评论 0原文

在 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

It's very straightforward to make one variable the result returned from a dialog in applescript, but is it possible to use the first and second letter as two separate variables and the rest of the result returned from the dialog as a third? Below there's a code example with what I want to do and approximately where I think I want to do it.

    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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无言温柔 2025-01-12 15:37:44

再简单不过了:

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

Couldn't be simpler:

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
想你只要分分秒秒 2025-01-12 15:37:44

甚至可以更简单: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

Can even be simpler :D including a check for the user's input

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文