I'm running macOS 11.5.2 on an M1 iMac. I've written an Automator app consisting of a Run Shell Script action followed by an Run AppleScript action to see if the java process is running and if not to let me know by text message.

I do this by a shell script that creates a file if the process is running. (If the process is not running the file isn't created.)

Next an AppleScript checks for the test file's existence. If it exists it deletes the file and returns with 0. If it doesn't exist it sends me a text message.

This works great when I run it from in Automator as a Workflow, but when I execute the Automator app that I created it gets as far as creating my test file and properly deleting it, but the text is not sent. I do see the app in System Preferences > Security & Privacy > Privacy > Automation allowing it to access Finder.

Here's the code that's in Automator:

Run Shell Script action:

number=$(ps aux | grep -v grep | grep -ci $PROCESS)

if [ $number -gt 0 ]
        echo Running > /Users/imac-m1/Desktop/Running.txt;

Then I pause for 2 seconds via Automator to give the filesystem a chance to create the file.


Run AppleScript action:

tell application "Finder"
    if exists POSIX file ("/Users/imac-m1/Desktop/Running.txt") then
        -- display dialog "it exists"
        tell application "Finder"
            delete the file "Running.txt" of the desktop
        end tell
        return 0
    end if
end tell

-- display dialog "Missing!"
tell application "Messages"
    set targetBuddy to "(860) 555-121T"
    set targetService to id of 1st account whose service type = iMessage
    set textMessage to "AARGGH! CrushFTP Java Not Found!!"
    set theBuddy to participant targetBuddy of account id targetService
    send textMessage to theBuddy
end tell

Any ideas?

  • I'd get rid of the Run Shell Script action completely and the tell application "Finder" block in the Run AppleScript action, replacing it with: if (do shell script "pgrep -ix 'java'; exit 0") is not "" then return Commented Aug 15, 2021 at 1:48
  • Thanks for the update. It certainly is much cleaner. Somehow when I made that change my problem went away. Don't know why.
    – DHK
    Commented Aug 15, 2021 at 19:00


You must log in to answer this question.

Browse other questions tagged .