Hi,
I’m converting two of my AS script bundles to portable Automator Services.
I expected quick work, just open an Automator Services workflow, copy the AS script, save, done.
Alas, nothing is ever easy. To my surprise, I dicovered that:
- service workflow bundles don’t have :Contents:Resouces: folders, just :Contents:, and don’t seem to find it if you add one.
- worse still, it can’t handle “path-to-me” as expected. Instead of pointing to the service workflow, it points to its runner.
note however, that “path-to-me” does behave normally in an Automator applet.
-- To test this as a service, copy the script to an Automator Service workflow and save it as "myService.workflow"
tell application "Finder"
activate
set MySelection to selection as alias list -- any selection will do, just to get access to the Service CM.
set mePath to (path to me as text) -- DOESN'T WORK as expected (by me, at lest) in an Automator Service workflow.
set the clipboard to mePath
-- When the AS is running within the open workflow, it points to the Automator --> HD-1:Applications:Automator.app:
-- When the AS is running within the Service, it points to its runner:
--> HD-1:System:Library:Frameworks:AppKit.framework:Versions:C:XPCServices:WorkflowServiceRunner.xpc:
-- This is my AS "path-to-me" workaound for an Automator Service. It works, but only a mother can like it.
-- ================================================================
set myServiceName to "myService.workflow"
-- if the service path is "Volume:Library:Services:myService.workflow"
set ServicesPath to (path to library folder as text) & "Services:"
set myServicePath to ServicesPath & myServiceName
-- if the service path is "Volume:Users:username:Library:Services:myService.workflow"
set userServicesPath to (path to library folder from user domain as text) & "Services:"
set myUserServicePath to userServicesPath & myServiceName
-- I use a custom icon here, as an easy way to check that the service is working.
if exists myServicePath then
set myItemPath to (myServicePath & ":Contents:my.icns") as alias
else if exists myUserServicePath then
set myItemPath to (myUserServicePath & ":Contents:my.icns") as alias
-- ================================================================
else
-- This is the usual "path-to-me" on-liner. It works in any Script Bundle, Applet, or Droplet.
set myItemPath to ((path to me as text) & "Contents:Resources:my.icns") as alias
end if
display dialog "Built path to icon" with icon myItemPath
end tell
To me, my contruption is an ugly replacement for the normal one-liner. Does anybody have a better idea?
Is there a better AS stand-in for the “path-to-me”, usable in a Service to point to the actual Service instead of its runner?