发布设置将文本返回到重复循环内的变量-OS X 10.9.x

乔希

该脚本的目标是:

  1. 询问用户他们想要多少个文本替换(“系统偏好设置”>“键盘”>“文本”)快捷方式。返回的文本被设置为我的变量“ gTextReplacementNum”的数字。参见我的第二个处理程序 “ HowMany()”

  2. 让用户提供文本替换快捷方式,并用文本替换所需数量的快捷方式。看到我的第三个处理程序 “ GetText()”

  3. 以用户提供的包含在变量中的文本为例,创建一个新的AppleScript文档,以完成所有繁重的工作。代码尚未编写;不在问题范围内。

  4. 然后,他们可以在Mac上启动个性化的AppleScript应用程序捆绑包,以自动填充文本替换首选项窗格。

我很难让它正常工作。我需要循环以不断将答案添加到列表中的变量或根据循环实例(例如,TextReturned_i,TextReturned_i + 1等)递增其名称的变量中。

我有足够的解释吗?

global gTextReplacementNum
set gTextReplacementNum to 0

# Main Logic Begins

try

    Start()

    HowMany()

    GetText()

on error errText number errNum
    display alert "Error " & errNum message errText

end try

# Main Logic Ends



# Handlers Begin

-- First Handler
on Start()
    display alert "Automated Text Replacement v1.0" message "Created by: Me
[email protected]" buttons {} giving up after 4
    display alert "About" message "This app will have you provide a text 'short cut' to replace with and replacement text. It then compiles all this into an application that can be run on any Mac.

    Would you like to continue?" buttons {"No", "Yes"} cancel button 1 default button 2
end Start


-- Second Handler
on HowMany()
    display dialog "How many text replacement shortcuts would you like?

    Please enter numericals only. (1, 2, 3)" default answer "" buttons {"Cancel", "Okay"} default button 2 cancel button 1
    copy the result as list to {ButtonPressed, TextReturned}
    set gTextReplacementNum to TextReturned as number
end HowMany

-- Third Handler
on GetText()
    repeat with i from 1 to gTextReplacementNum as number
        display dialog "What text would you like to replace?
        (this is your shortcut)" default answer "" buttons {"Cancel", "Okay"} default button 2 cancel button 1
        set TextShortcut to text returned of result as list

        display dialog "What is the replacement text?
        (this is what the shortcut fills out)" default answer "" buttons {"Cancel", "Okay"} default button 2 cancel button 1
        set TextReplaced to text returned of result as list
    end repeat
end GetText

# Handlers End
jweaks

在GetText()处理程序中,您每次都替换值TextShortcut和TextReplaced。你需要

set aList to aList & newValue

在重复循环中建立清单。

同样,此处理程序从不返回这两个列表的值。因此,我建议您使用您的方案,同时将这两个变量设置为全局变量。因此,完整的更改是:1.添加到声明中:

global gTextReplacementNum
global gTextShortcut
global gTextReplaced

set gTextReplacementNum to 0
set gTextShortcut to {}
set gTextReplaced to {}

和2.编辑您的GetText()处理程序:

-- Third Handler
on GetText()
    repeat with i from 1 to gTextReplacementNum as number
        display dialog "What text would you like to replace?
        (this is your shortcut)" default answer "" buttons {"Cancel", "Okay"} default button 2 cancel button 1
        set gTextShortcut to gTextShortcut & (text returned of result)

        display dialog "What is the replacement text?
    (this is what the shortcut fills out)" default answer "" buttons {"Cancel", "Okay"} default button 2 cancel button 1
        set gTextReplaced to gTextReplaced & (text returned of result)
    end repeat
end GetText

另一种方法是读取制表符delim文件,并使用标准脚本从该文件开始工作。就像是:

property fileName : "shortcuts.txt"

set filePath to (path to desktop as string) & fileName
set theData to read file filePath

set theRecords to paragraphs of theData
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to tab

repeat with thisPair in theRecords
    set {theShortcut, theReplacement} to text items of thisPair
    setKeyboardPref(theShortcut, theReplacement)
end repeat
set AppleScript's text item delimiters to oldDelim

on setKeyboardPref(theShortcut, theReplacement)
    -- set up the pair
    display dialog theShortcut & return & theReplacement
end setKeyboardPref

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

发布设置将文本返回到重复循环内的变量-OS X 10.9.x

来自分类Dev

Win10与OS X中纯文本的区别

来自分类Dev

在C ++中打印9x9数组而不是10x10数组?

来自分类Dev

查找同时满足9x <10 && 7.5x <8的X的最大值

来自分类Dev

在OS X上设置g ++

来自分类Dev

如何在Windows 10上安装mac OS X ElCapitan

来自分类Dev

OS X命令作为别名失败,并显示错误'9:13:执行错误:未定义变量Base。(-2753)'

来自分类Dev

Mac OS X重复软件安装失败

来自分类Dev

根据用户输入的OS X重复

来自分类Dev

OS X系统偏好设置URL方案

来自分类Dev

在OS X Yosemite中设置umask

来自分类Dev

如何设置OS X终端颜色主题?

来自分类Dev

需要OS X快捷方式/设置

来自分类Dev

在Mac OS X Mavericks上设置Kibana

来自分类Dev

在OS X 10.9上设置PATH无效

来自分类Dev

在MAC OS X中设置Openfire

来自分类Dev

Mac OS X如何设置$ PATH的值?

来自分类Dev

需要OS X快捷方式/设置

来自分类Dev

OS X IntelliJ IDEA颠覆设置

来自分类Dev

在OS X Yosemite中设置umask

来自分类Dev

在OS X的Zsh中设置PATH

来自分类Dev

为 make OS X 设置 JDK 路径

来自分类Dev

x的返回值= os.system(..)

来自分类Dev

OS X:python ctypes全局变量

来自分类Dev

将CMake移植到OS X Yosemite

来自分类Dev

将CMake移植到OS X Yosemite

来自分类Dev

在Mac OS X 10.9上,什么可以使nanosleep准确地在10秒钟内漂移

来自分类Dev

在Mac OS X 10.9上,什么可以使nanosleep准确地在10秒钟内漂移

来自分类Dev

如何将9x9阵列拆分为9个3x3组件