【问题标题】:Persistent variable storage in AutomatorAutomator 中的持久变量存储
【发布时间】:2012-10-30 19:04:36
【问题描述】:

是否可以在自动化工作流(特别是服务流)中存储持久值?

似乎是常规自动机变量are not persistent;例如,尝试使用 an applescript chunk which has a property (通常会持续存在)实际上也不会在 Applescript 中持续存在该属性(在测试中有效,但是当您运行服务时,该值不会持续存在)。

有什么想法吗?

【问题讨论】:

    标签: macos shell applescript automator


    【解决方案1】:

    您可以使用脚本对象将数据存储在不碍事的地方。

    on run
        -- Path of script which holds data
        set thePath to (path to desktop as text) & "myData.scpt"
        --set thePath to (path to preferences as text) & "myData.scpt" -- better
    
        script theData
            property xxx : missing value
        end script
    
        try
            set theData to load script file thePath
        on error
            -- On first run, set the initial value of the variable
            set theData's xxx to 5
        end try
    
        -- change the value of the variable
        set theData's xxx to (theData's xxx) + 1
    
        -- save your changes
        store script theData in file thePath replacing yes
        return theData's xxx
    end run
    

    【讨论】:

    • +1 我没有想到这一点,它可能非常适合复杂的数据类。
    • 谢谢...脚本改编自AppleScript: The Definitive Guide中的示例
    • 如果其他人像我一样在学习 AppleScript replacing yes 意味着在必要时覆盖
    猜你喜欢
    • 2011-03-04
    • 2010-09-27
    • 2011-02-27
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    • 2013-04-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多