How do I determine which application launched automator service?
Buscar's comment made me check the process hierarchy and it turns out, a service is a sub-sub-sub process of the application that launched it.



So, even though in many cases, a query for the frontmost application may be ok, I think looking at the process tree is better.

Here is some sample code from a test Service Workflow that for me appears to work every time...

on run {input, parameters}

    set arpid to (do shell script "echo $PPID")
    display dialog "Automator Runner PID is: " &amp; arpid

    set srpid to (do shell script "ps -o ppid -p " &amp; arpid &amp; " | tail -1")
    display dialog "Service Runner PID is: " &amp; srpid

    set appid to (do shell script "ps -o ppid -p " &amp; srpid &amp; " | tail -1")
    display dialog "Application PID is: '" &amp; first word of appid &amp; "'"

    tell application "System Events"
        set activeApp to (name of first process whose unix id is (appid as integer))
    end tell

    display dialog activeApp

    return input
end run