Skip to main content
Question

Deploy Automator .Workflow file


Forum|alt.badge.img+4

Hello,

I've made a service through Automator, and binded it to a keyboard shortcut.

Would there be any simple way to make this available through say self service? Or deploy it with a policy?

I've tried googling around a little and read about the installation of a .workflow file, so I think I could throw something together but I thought I'd see if anyone has already tried something similar.

Thanks!

4 replies

mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • 7886 replies
  • December 5, 2016

Hi. I assume you want to do more than simply deploy the workflow file onto the Mac. It sounds like you also want to deploy the keyboard shortcut binding, correct?

If so, those shortcuts are stored in a pbs.plist file that lives in the user's /Library/Preferences/ folder.

You have a few options. You can potentially capture that pbs.plist file on a clean system that doesn't have any other custom keyboard shortcuts, and deploy it in a DMG file with the Fill Existing Users option checked. This will push the pbs.plist file into place for each user account. The one big issue with doing this is that you run the risk of overwriting any custom keyboard shortcuts the user may have put in place on their own.
Another option is to write in the shortcut settings to the pbs.plist file (if it exists) using PlistBuddy (defaults can't really do it as its too complicated)

Along with the above steps, you'd also of course need to deploy the .workflow file into the user's /Library/Services/ directory.

If I recall when I had done this, I think a service or application needs to be restarted in order for the Finder to recognize the newly installed service and shortcut. I think actually its the Finder itself that needs the restart, but I'd need to go back and look again.

Note that I haven't done this since around 10.9 and early 10.10, so I don't know if things have changed with 10.11 and 10.12 now.


Forum|alt.badge.img+4
  • Author
  • Contributor
  • 11 replies
  • December 5, 2016

@mm2270

Thanks for the quick reply! You are correct in that I also want to deploy the keyboard shortcut binding.

That looks like a great way of going about it but the risk of overwriting any custom keyboard shortcuts is an unfortunate one.

I guess I'll have to work with it a bit and see if I can get the desired result with minimal potential for things to go wrong.


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • 7886 replies
  • December 5, 2016

@alaiuppa Just so you don't need to build this all from scratch, here is a version of the script I had done for this, with a few modifications so as to make it into a kind of template to use. This was contained within a pkg installer as a postinstall script. What it did was deploy some files into /private/tmp/ and then the script would either move files into place, or make the needed changes to the plist file. In this script I renamed the workflow to just "Service.workflow" You'd need to rename it to what you called your actual workflow file.

Also, in the section where it uses PlistBuddy to write in the keyboard shortcut, I first examined the pbs.plist file to see how the shortcut was written in. In the script below, you'll see it added in a string like "@~^l" which becomes Command-Option-Control-L. Again, I would do a defaults read against the pbs.plist file that has the shortcut added to examine how it added it so you can duplicate that in a script.

1#!/bin/sh
2
3## Get the logged in username
4currUser=$(/usr/bin/stat -f%Su /dev/console)
5
6## Check for a 'Services' folder in the user's home directory. Create one if necessary
7
8if [ ! -d /Users/$currUser/Library/Services ]; then
9 echo "Creating Services directory for $currUser"
10 mkdir /Users/$currUser/Library/Services
11 sudo chown -R $currUser /Users/$currUser/Library/Services
12fi
13
14## Check to see if the workflow file was installed in /tmp
15## and copy it to the current user's home Library folder
16if [ -d /private/tmp/Service.workflow ]; then
17 sudo cp -R /private/tmp/Service.workflow /Users/$currUser/Library/Services/
18 echo "Copied the workflow to $currUser's Services folder"
19 sudo chown -R $currUser /Users/$currUser/Library/Services/Service.workflow
20 echo "Set permissions on the workflow to $currUser as owner"
21 sudo chmod -R go-rwx /Users/$currUser/Library/Services/Service.workflow
22 echo "Set access on the workflow for $currUser"
23else
24 ## Exit the rest of the installation if the workflow wasn't there to copy
25 echo "The Service workflow was not found. Exiting installation..."
26/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "Installation failed" -description "We seem to have run into a problem getting the service installed for you. Try running the Self Service installation again. If you continue to see this error, contact support so we can help correct this for you." -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertCautionIcon.icns" -button1 "OK" -defaultButton 1
27 exit 1
28fi
29
30## Taking care of the shortcut for the LockScreen workflow in the current user's pbs.plist file
31if [ ! -e /Users/$currUser/Library/Preferences/pbs.plist ]; then
32 if [ -e /private/tmp/pbs.plist ]; then
33 cp /private/tmp/pbs.plist /Users/$currUser/Library/Preferences/
34 theDate=$(date +"%s")
35 /usr/bin/defaults write /Users/$currUser/Library/Preferences/pbs NSServicesUserDirectoryModDate -float $theDate
36 chown $currUser /Users/$currUser/Library/Preferences/pbs.plist
37 chmod go-rwx /Users/$currUser/Library/Preferences/pbs.plist
38 else
39 ## if we couldn't find an existing pbs.plist file for the user and the file was missing from /tmp
40 ## then we exit the rest of the installation
41 echo "The pbs.plist file was not found. Exiting..."
42 exit 1
43 fi
44 else
45 ## If we found an existing plist file for the user, use PlistBuddy to add the keyboard shortcut instead
46 /usr/libexec/PlistBuddy -c 'Add :NSServicesStatus:"(null) - Service - runWorkflowAsService":key_equivalent string "@~^l"' /Users/$currUser/Library/Preferences/pbs.plist
47 echo "Added LockScreen shortcut to $currUser's existing plist file"
48 ## Update the date modified string for the user's Services directory
49 theDate=$(date +"%s")
50 /usr/bin/defaults write /Users/$currUser/Library/Preferences/pbs NSServicesUserDirectoryModDate -float $theDate
51 chown $currUser /Users/$currUser/Library/Preferences/pbs.plist
52 chmod go-rwx /Users/$currUser/Library/Preferences/pbs.plist
53fi
54
55## Now we check to make sure everything is in place
56if [ -e /Users/$currUser/Library/Services/Service.workflow ]; then
57 echo "The Service was installed"
58 serviceFile="Yes"
59fi
60
61if [ -e /Users/$currUser/Library/Preferences/pbs.plist ]; then
62 echo "The shortcut file exists"
63 shortcutFile="Yes"
64fi
65
66sleep 2
67killall Finder
68
69## Final clean up stage
70rm -R /private/tmp/Service*
71rm /private/tmp/pbs.plist

See if you can use this to get you where you need to go. Remember that I have not used this since around 10.10, so it may need work for 10.11 and 10.12.


Forum|alt.badge.img+16

@alaiuppa @mm2270

Not sure if either of you care about this conversation anymore but I needed to find a solution like this. The only addition I had to make to your script to make it work on 10.12 was to reload the com.apple.pbs.plist which updated the connection between the pbs.plist shortcut and the new service.

I also made a few tweaks like updating the keyboard shortcut to be in line with High Sierra's lock screen key command. Thanks @mm2270 for the script, saved me a lot of time and brainpower!

1#!/bin/sh
2
3## Get the logged in username
4currUser=$(/usr/bin/stat -f%Su /dev/console)
5
6## Check for a 'Services' folder in the user's home directory. Create one if necessary
7
8if [ ! -d /Users/$currUser/Library/Services ]; then
9 echo "Creating Services directory for $currUser"
10 mkdir /Users/$currUser/Library/Services
11 sudo chown -R $currUser /Users/$currUser/Library/Services
12fi
13
14## Check to see if the workflow file was installed in /tmp
15## and copy it to the current user's home Library folder
16if [ -d /private/tmp/ScreenSaver/LaunchScreenSaver.workflow ]; then
17 sudo cp -R /private/tmp/ScreenSaver/LaunchScreenSaver.workflow /Users/$currUser/Library/Services/
18 echo "Copied the workflow to $currUser's Services folder"
19 sudo chown -R $currUser /Users/$currUser/Library/Services/LaunchScreenSaver.workflow
20 echo "Set permissions on the workflow to $currUser as owner"
21 sudo chmod -R go-rwx /Users/$currUser/Library/Services/LaunchScreenSaver.workflow
22 echo "Set access on the workflow for $currUser"
23else
24 ## Exit the rest of the installation if the workflow wasn't there to copy
25 echo "The Service workflow was not found. Exiting installation..."
26 exit 1
27fi
28
29## Taking care of the shortcut for the LockScreen workflow in the current user's pbs.plist file
30if [ ! -e /Users/$currUser/Library/Preferences/pbs.plist ]; then
31 if [ -e /private/tmp/ScreenSaver/pbs.plist ]; then
32 cp /private/tmp/ScreenSaver/pbs.plist /Users/$currUser/Library/Preferences/
33 theDate=$(date +"%s")
34 /usr/bin/defaults write /Users/$currUser/Library/Preferences/pbs NSServicesUserDirectoryModDate -float $theDate
35 chown $currUser /Users/$currUser/Library/Preferences/pbs.plist
36 chmod go-rwx /Users/$currUser/Library/Preferences/pbs.plist
37 else
38 ## if we couldn't find an existing pbs.plist file for the user and the file was missing from /tmp
39 ## then we exit the rest of the installation
40 echo "The pbs.plist file was not found. Exiting..."
41 /Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -title "Installation failed" -description "The Screen Saver shortcut did not install properly." -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertCautionIcon.icns" -button1 "OK" -defaultButton 1
42 exit 1
43 fi
44 else
45 ## If we found an existing plist file for the user, use PlistBuddy to add the keyboard shortcut instead
46 /usr/libexec/PlistBuddy -c 'Add :NSServicesStatus:"(null) - LaunchScreenSaver - runWorkflowAsService":key_equivalent string "@^q"' /Users/$currUser/Library/Preferences/pbs.plist
47 echo "Added LockScreen shortcut to $currUser's existing plist file"
48 ## Update the date modified string for the user's Services directory
49 theDate=$(date +"%s")
50 /usr/bin/defaults write /Users/$currUser/Library/Preferences/pbs NSServicesUserDirectoryModDate -float $theDate
51 chown $currUser /Users/$currUser/Library/Preferences/pbs.plist
52 chmod go-rwx /Users/$currUser/Library/Preferences/pbs.plist
53fi
54
55## Now we check to make sure everything is in place
56if [ -e /Users/$currUser/Library/Services/LaunchScreenSaver.workflow ]; then
57 echo "The Service was installed"
58 serviceFile="Yes"
59fi
60
61if [ -e /Users/$currUser/Library/Preferences/pbs.plist ]; then
62 echo "The shortcut file exists"
63 shortcutFile="Yes"
64fi
65
66sleep 2
67killall Finder
68
69/bin/launchctl unload /System/Library/LaunchAgents/com.apple.pbs.plist
70/bin/launchctl load /System/Library/LaunchAgents/com.apple.pbs.plist
71
72## Final clean up stage
73rm -rf /private/tmp/ScreenSaver/

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings