Monitor downloads on Terminal and Restart

How can I create a KM Macro that when executed will check if a download by youtube dl is in progress or has stopped ?

Assuming you know the file path of the downloading file, then you would basically write a sequence like:

  • Get File Attribute action to get the size of the file.
  • Repeat a million times
    • Pause 5 seconds
    • Get File Attribute action to get the size of the file.
    • If calculation New Size == Old Size then
      • Break From Loop
    • Set variable Old Size to calculation NewSize
3 Likes

Thank you for the KM Script.

Meanwhile I tried bash script and and compared Timestamp of file with current time.

#!/bin/bash

VAR1=$(ls -lt <(echo "$KMVAR_ytd_download_folder") | head -2 | tail -1 | awk '{print $6,$7,$8}' | sed -e 's/ //g')
VAR2=$(date | cut -b 5-16  | sed -e 's/ //g')

if [ "$VAR1" == "$VAR2" ]; then
    echo "INPROGRESS"
else
    echo "STOPPED"
fi

Also would like to know if there is a way to send a notification to Apple Watch or iPhone using Keyboard Maestro ?

[Edit]: The above script has a bug because ls uses mtime ?

1 Like

I use Pushover for this. Works great.

Here's a plugin that allows you to send Pushover notifications from KM:

3 Likes

@noisneil
Thanks. That app is super cool.

[Off-topic]Can Pushover be used from a unity game to push One-Time-Passwords to players ?

I'm not really sure what that means, but you can try the free demo to find out...

@noisneil
Oops. I thought you were the creator of PushOver plugin & App. My bad ;]

@peternlewis

The Get File Attribute action throws an NSCocoa.. error if you give it a filePath as a string

So in the-end, I had to use :diamonds: RUBY :diamonds:

  1. get fileSize01
  2. sleep(2) # Ruby Sleep method
  3. get fileSize02
  4. compare fileSizes

Final Working Solution :heart_eyes:

  • Execute Shell Script and set output to variable : ytd_Progress
  • Use Ruby to get the size of the file now & 1 sec later
    * FileSize01 now
    * Using Ruby's sleep(2)
    * FileSize02 now
    * Compare the fileSize
    * PUTS a String either "INPROGRESS" or "STOPPED"
  • Show KM Alerts based on Variable ytd_Progress

Say what? What do you mean by this?

@peternlewis

In the action, I used a variable as `%Variable%ytd_filePath%
And it showed an NSCocoa.. Error

I've never seen or heard of anything like that, can you send me some more information - an image of the exact error, anything reported in the Engine.log or Editor.log, and any diagnostic files that are created.

Probably send them to support@stairways.com

Thanks.

@peternlewis
What do you mean by "diagnostic files" ?
I don't know where to find those.

Here is Engine.log showing the Error (: Now I know I can look at Engine.log to debug the script ) :nerd_face:

[ Edit : Exact filepath & username in Log files changed as it would reveal too much "context" to the public ]

2023-10-02 06:56:12 Action 1231 failed: Get File Attribute failed to get attributes for /Users/xojo/Documents/unity/shaders/Specularity.f140.m4a.part
with error Error Domain=NSCocoaErrorDomain Code=260 "The file “Specularity.f140.m4a.part
” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/xojo/Documents/unity/shaders/Specularity.f140.m4a.part
, NSUnderlyingError=0x600003baa8b0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
2023-10-02 06:56:12 Get File Attribute failed to get attributes for /Users/xojo/Documents/unity/shaders/Specularity.f140.m4a.part
with error Error Domain=NSCocoaErrorDomain Code=260 "The file “Specularity.f140.m4a.part
” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/xojo/Documents/unity/shaders/Specularity.f140.m4a.part
, NSUnderlyingError=0x600003baa8b0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}} in macro “Check youtube-dl” (while executing Get File Size to Variable “ytd_latest_file”).

OK, it is reporting that “there is no such file”.

That could be because the path is wrong (maybe a typo somewhere), or it could be that it is in the Documents folder, and Keyboard Maestro Engine does not have access to it (ensure it has access to the Documents folder (or Full Disk Access) in the Security & Privacy settings).

Am not sure if the problem is about finding the *.part file with the Get Attribute Action.

Because the it works with the Ruby script

Thanks much for the help.

@peternlewis

The Problem was the name of the File being downloaded was "Shader Specularity.f140.m4a.part"
With the bash script (awk and sed and cut) it was splitting the string on spaces, so the string "Shader" was omitted from the filename. With Ruby debugging the Filename was easier.

1 Like