Is it possible to create a macro which determines if a checkbox in a SP menu is checked or not

Hello, this is just an example. I do not want to write a macro for this specific task.

I want to better understand the capabilities of KBM.

Is there a simple way to have a macro read whether Wake for Network Access is checked or not ?

thank you

image

Hey @ronald,

Sure. Use a found image action.

-Chris

1 Like

thank you for your reply.

sorry, I don't understand.

I often use click at found image, but 'read' at found image, and generate a notification 'Wake for Network access is checked' ?

As they say, there's more than one way to s̶k̶i̶n̶ ̶a̶ ̶c̶a̶t̶ find an image:

Notification Based on Found Image.kmmacros (66.5 KB)
image

1 Like

[ "$( pmset -g | awk '/womp/ {print $2;}' )" = "1" ] && printf "true" || printf "false"

If you're goal is not so much to detect the status of the checkbox, but rather the setting that the checkbox represents, then this retrieves that setting. true equates to the checkbox being checked (i.e. Wake For Network Access is active); false otherwise. If you're happy with simply 1 and 0 instead of true and false, the shell code can be simplified to:

pmset -g | awk '/womp/ {print $2;}'

I appreciate this might not be what you had in mind if all you wish to observe is KM's capabilities rather than a solution to a problem.

3 Likes

it works very nicely. thanks.

If I understand correctly, the script is totally dependant on my understanding shell scripting. There is nothing obvious / recognizable to edit, unless you have a suggestion on how I could acquire a very narrow understanding of shell scripting applicable to mac system preferences windows which would allow me to edit the script and adapt to other windows. I have too much on my plate and am not going to embark on learning the ins and outs of shell scripting.

If I may trouble you with another script question.
I have this script which displays free space on my hard drive which I currently need because I am running out of space and have to check regularly.

df / | awk '{ print $5 }' | tail -n 1

It works well within a KBM macro but the result is displayed as a % which is not great.

  • how would I edit it so that it displays the amount of free space in GB instead of %. I tried playing around with it but got nowhere.
  • would you know why KBM notifications are always transient (banner type). Is there any way to create alert style notifications ?

Thanks very much for your help

image

thank you. Now I understand the logic. You told me about if then else in the past, and I forgot about it.
I will flagellate myself today to insure I remember next time.
thanks a lot.

@gglick
now I'm confused. I thought by reading the actions that the macro would only work if the window in question was open which it is not (I closed sys pref), and if it was open, I could see the setting and would not need a macro.

Here's what each part of the command does:

  • [ df / ] Displays information about the free space for the disk mounted at /, i.e. your main startup disk. The information is tabulated and will look something like this:

    Filesystem   512-blocks      Used Available Capacity iused               ifree %iused  Mounted on
    /dev/disk1s1  975221040 865578296  99873792    90% 1419161 9223372036853356646    0%   /
    
  • [ awk '{ print $5 }' ] This takes the output above and processes each line, printing only the text contained within the fifth field (column). The fifth field in the header line is "Capacity", and in the line below is "90%".

  • [ tail -n 1 ] This takes the output from the awk command, which would have been this:

    Capacity
    90%
    

    and prints only the final line, which is what gives you your overall output.

If run the df command using the -H option, this returns the information as so-called Human Readable output, and looks like this:


    Filesystem     Size   Used  Avail Capacity iused               ifree %iused  Mounted on
    /dev/disk1s1   499G   443G    51G    90% 1419160 9223372036853356647    0%   /

I've bolded the information that will be of most interest to you, namely the total size of your hard disk; the amount of space used; and the amount of space available; each of which are evaluated in gigabytes, denoted by the suffix "G".

Specifically, the fourth column is the one containing the amount of free space remaining. Thus, with two small edits to the original command, you'll get the output returned as "51G" (or whatever remains on your hard drive):

df -H / | awk '{ print $4 }' | tail -1

You can also retrieve the information with AppleScript (I'm not suggesting this is better, but it's useful to have more than one option at your disposal):

tell application id "com.apple.systemevents" to return ¬
    (startup disk's free space) * 100 div (2 ^ 30) / 100

startup disk's free space returns the information in bytes. The numerical manipulation yields the equivalent gigabyte value, to 2 decimal places, e.g. 52.24. There's a slight discrepancy between this result and the one given by df, which I'm not able to account for.

No, sorry.

1 Like

extremely interesting and informative. thank you very much

just a thought about the discrepancy which is not am important issue

1- perhaps Gi vs GB ?

2- APFS time machine snapshots are for example counted if the calculation of Pathfinder disk size, but not with Finder

thanks again very much