macOS - shell script and AppleScript script not working together

Hi All,

I have:

  • shell script
    – using terminal runs fine manually using "sh ~/Desktop/tm.sh

  • AppleScript
    – creates the file but doesn’t output the date into the file

Question:

  • what am I doing wrong and why is it not working in the AppleScript?

shell script - tm.sh
– takes the latest backup date for Time Machine and outputs it to a file (tmDate.txt) on the desktop.

Applescript

do shell script "sh ~/Desktop/tm.sh"

In my opinion, the tilde is recognized by the Terminal (as the path to the home folder). But for the do shell script command, it means nothing. That is, you should most likely specify the path to your home folder instead of the tilde:


set thePath to quoted form of (POSIX path of (path to home folder) & "Desktop/tm.sh")

do shell script "sh " & thePath

thanks for the response but I still get an empty file with no date.

using:

set thePath to quoted form of (POSIX path of (path to home folder) & "Desktop/tm.sh")

do shell script "sh " & thePath

What happens when you indicate the full path to sh ?

do shell script "/bin/sh " & allPath

set thePath to quoted form of (POSIX path of (path to home folder) & "Desktop/tm.sh")

do shell script "/bin/sh " & thePath

creates the file but it’s empty.

I ran your sh script in Terminal and it created an empty tmDate.txt file on my desktop. Perhaps this is because I do not make any backup at all.

Ok here’s the solution: :rolleyes:

Solution:

  • Privacy setting wasn’t set for Full Disk Access

for Script Editor or Automator.

Once that is set then it works as desired.