Persistent variable storage in Automator

主宰稳场 提交于 2020-02-16 05:47:49

问题


Is it possible to store a persistent value in an automator workflow (specifically for a service flow)?

It seems that regular automator variables are not persistent; for instance trying to use an applescript chunk which has a property (which normally persists) does not actually persist the property in Applescript either (works in testing, but when you run the service the value doesn't persist).

Any ideas?


回答1:


You can use script objects to store your data in an out of the way place.

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


来源:https://stackoverflow.com/questions/13325386/persistent-variable-storage-in-automator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!