Persistant variable storage in Automator

2019-03-06 00:22发布

Is it possible to store a persistant value in an automator workflow (specifically for a service flow)? Seems that regular automator variables are not persistant and trying for instance to use an applescript chunk which has a property (which are normally persistant) does not actually persist the property in the Applescript either (works in testing, but when you run the service the value doesn't persist). Any ideas?

1条回答
Animai°情兽
2楼-- · 2019-03-06 01:18

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

Automator

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
查看更多
登录 后发表回答