I came across this thread and saw a few parts that really jumped out at me as very inefficient so I took a few minutes to optimize it.
ioreg -l -w 0 command is extremely inefficient. Running
ioreg, especially showing all properties, dumps a LOT of text. It is like opening a fire hydrant then using a straw to get a drink!
A test run took over 2.5 seconds and dumped over 18,000 lines which came to 4.2MB.
A better option is to only have it return only the specific section that holds the value we need, in this case the IOResources object and only the top entry. That command is
ioreg -n IOResources -r -d 1 -l and a test run was over 100 times faster (0.021 seconds, 34 lines)
Instead of sending the output text to the
perl programs, keep it internal as a variable and grab only the process ID number using regex.
If it found a process ID number, then get the application name. Another optimization is for the
ps lookup. We don't need to get a list of all process by all users and then filter out what we need. Using the
-p option with the process ID will return only that process.
Here is what I've come up with. The Execute Shell Script action can be used in your own macro if you need to check if Secure Input is on or not. I hope someone finds it useful.
Is Secure Input enabled.kmmacros (4.0 KB)