macOS - AppleScript + shell script + calendar alarm not returning value but working in automator

So I have a shell script called > tm.sh which gets the last time time machine successfully backed.
This works fine in the
  • shell,

  • script editor,

  • automator

doesn't work as a calendar alarm.

I'm unsure why the "do shell script" line is not working

tm.sh
Code Block
#!/bin/sh
enabled=`/usr/bin/defaults read /Library/Preferences/com.apple.TimeMachine AutoBackup`
if [ "$enabled" == "1" ];then
lastBackupTimestamp=`date -j -f "%a %b %d %T %Z %Y" "$(/usr/libexec/PlistBuddy -c "Print Destinations:0:SnapshotDates" /Library/Preferences/com.apple.TimeMachine.plist | tail -n 2 | head -n 1 | awk '{$1=$1};1')" "+%Y-%m-%d %H:%M:%S"`
echo "$lastBackupTimestamp"
else
echo "<result>Disabled</result>"
fi

My calendar alarm
Automator > New > Calendar alarm > run apple script

Calendar Alarm AppleScript
Code Block
on callDateSeperator(dateChange)
set yN to text 1 thru 4 of (dateChange as text)
set mN to text 6 thru 7 of (dateChange as text)
set dN to text 9 thru 10 of (dateChange as text)
return {yN, mN, dN}
end callDateSeperator
on run {input, parameters}
set timeMachineLastDate to (do shell script "sh ~/Desktop/tm.sh")
set tmDate to callDateSeperator(timeMachineLastDate)
display dialog (item 1 of tmDate) & (item 2 of tmDate) & (item 3 of tmDate)
return input
end run

I have given full disk access to
  • automator

  • calendar

error: this error comes because "timeMachineLastDate" has no value.
The action: "Run AppleScript" encountered an error: Can't get text 1 thru 4 of ""."
macOS - AppleScript + shell script + calendar alarm not returning value but working in automator
 
 
Q