0

I have a workflow which is installed as a Service. It is used to call code in my AppleScript applet. The Service has one action: a "Run AppleScript" action. I update the Service quite often with improvements.

I need a way to know that the installed version of my Service is old. One way might be to give it a "version".

I have tried many ways, none of which worked. In particular, usually there is a CFShortVersionString key in an app's info.plist file. I can add that to my Service's info.plist file. But, when I open my Service in Automator.app, make some changes and then save, all my custom entries in the info.plist file are deleted.

Is there an editor for Automator workflows that does not remove custom keys in the info.plist file ?

Thanks.

UDATE: Adding a variable to the workflow is a good idea. But, I can't it working for me. Yesterday, I added the variable called "Version" and gave it a value "1.21". Today, the variable is still there but is empty. Probably because I still do not understand how it all works and I made a mess of it.

In the end, a separate file in the service's bundle containing just the version string is easy for me as my AppleScript applet can read it without having to parse a complicated XML file (either as plain text or using System Events).

Also, I still don't know how developers create workflows which DO contain version and other keys inside the info.plist file. Automator removes those keys and so developers must be using another tool – Xcode ?

Have also found some services that contain a "version.plist" file. I have Googled for hours but, can find no documentation on the "version.plist" file content – which seems to duplicate some keys inside info.plist. The "version.plist" file does not seem to be used by Finder. In an example service provided by Apple, if I delete the CFBundleShortVersionString from the info.plist file, but retain the version.plist file, Finder's Get Info shows no version.

UPDATE 2: Apparently version.plist is used by Installer. More detail here: http://mirror.informatimago.com/next/developer.apple.com/documentation/DeveloperTools/Conceptual/SoftwareDistribution/Concepts/sd_pkg_version_info.html

Can't find that detail anywhere on developer.apple.com so, it might be out-of-date/wrong.

7
  • Didn’t I answer this before? The Info.plist is not the place for dynamic user stuff, so Automator (also Script Editor) doesn’t consider that before resetting it to whatever the current app settings are. Another option would be to look at something in the workflow, such as script text or a variable.
    – red_menace
    Feb 10 at 2:05
  • Why can not the version be stored as a comment in the AppleScript? Feb 10 at 11:49
  • red_menace, thanks. Yes, you've replied elsewhere and been very helpful. Sorry, I've been getting desperate and so spraying my question in a few places. David Anderson, thanks. Yes, that is one option on my list. I'll look at it again.
    – Garry
    Feb 11 at 2:51
  • If that solution worked, I can post it here so that this topic can be marked as answered.
    – red_menace
    Feb 11 at 22:36
  • Yes, it does work. Your AS code especially is sound. I've put commentary in my post.
    – Garry
    Feb 12 at 2:33

1 Answer 1

0

The Info.plist is for application settings, you are wanting to set a version for a document (workflow, script, etc).

In an Automator workflow package, the /Contents/document.wflow file is an XML property list that declares the various actions and their settings (such as the script for the Run AppleScript action), action connections, workflow metadata, and variables. This property list (or parts of it) can be read into a regular AppleScript list or record.

Possible solutions:

  1. A variable can be added to the workflow. Variables can be dynamically set by the workflow, in which case they will only have values when the workflow runs, or more persistent variables can be created by right-clicking in the variable pane and editing (a couple of the built-in variables can be dragged to the pane, but would need to be edited anyway). A script could look at the document.wflow file for the variable name in the list of variables (there will be a variables key) and get its value.

  2. A comment can be added in a Run AppleScript action's script. This works similar to adding a variable, the difference is that a script would need to search for the action in the list of actions (there will be an actions key), get the action's source script, and then look for the comment. It isn't much more difficult to get the script text, it is just buried a bit deeper in the hierarchy (you can check out the record structure in the Script Editor's log).

  3. Add a text file containing the version to the document package/bundle. Added files appear to be left alone, but a couple of disadvantages are that there would be another file to edit, and the version would not be apparent when working with the script or workflow.

  4. An extended attribute can be added to the file, for example, /usr/bin/xattr -w com.myservice.version 2.9 /path/to/workflow. This also appears to be left alone, a (dis)advantage may be the usage of the Terminal or a shell script to read and write the attribute.

Note that the Finder doesn't use versions for documents, and doesn't know about custom attributes, so none of the above would show up in a Get Info window.

The following example uses the Property List Suite from System Events to get lists of records from the property list file, which are used to get the version text from a variable or script text from a Run AppleScript action (adjust the name/text as desired):

on run -- example
   set plistFile to (choose file with showing package contents) -- get the document.wflow file
   # return scriptComment(plistFile) -- uncomment to use the script text
   return variableComment(plistFile)
end run

# Get version from a variable - the variable needs to be persistent (not generated by the workflow).
on variableComment(plistFile)
   tell application "System Events" to set variablesList to (get value of property list item "variables" of property list file (plistFile as text)) -- a record for each workflow variable
   if variablesList is not in {{}, missing value} then repeat with aRecord in variablesList
      try -- skip if no name or value key (built-in or not persistent)
         if |name| of aRecord is "Version" then -- or whatever
            return first item of value of aRecord -- the value is a list
         end if
      end try
   end repeat
   return missing value -- not found or no value
end variableComment

# Get version from script text - should be at the beginning of the first 'Run AppleScript' action.
on scriptComment(plistFile)
   tell application "System Events" to set actionsList to (get value of property list item "actions" of property list file (plistFile as text)) -- a record for each workflow action
   if actionsList is not in {{}, missing value} then repeat with aRecord in actionsList
      set theAction to action of aRecord -- base key
      if BundleIdentifier of theAction is "com.apple.Automator.RunScript" then
         repeat with aParagraph in paragraphs of (source of ActionParameters of theAction)
            if aParagraph contains "# Version" then -- or shebang, whatever
               return last word of aParagraph -- or wherever it is in the text
            end if
         end repeat
      end if
   end repeat
   return missing value -- not found or no value
end scriptComment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .