07-28-2021 03:44 AM - edited 07-28-2021 05:01 AM
Hey,
I'm looking for a better way to get all process IDs of all opened windows from a user then using this Applescript:
osascript -e 'tell application "System Events" to get unix id of every application process whose visible is true and name is not "Finder"'
I don't want to use AppleScript or not using System Events, because it needs to be "allowed" by the user or you need to create a PPPC profile, which i want to avoid.
Any idea?
Solved! Go to Solution.
Posted on 07-30-2021 06:52 AM
After hours of not getting a correct PPPC profile and still getting the **bleep** pop up, I found another solution for this problem:
@franton together with @talkingmoose found a nice way to not use osascript to get (almost) the same result.
Almost, as in they are not using the pids but the process names. Which i guess doesn't make a big difference at the end.
Check the script here: https://github.com/franton/Mac-Patcher-and-Upgrader/blob/e78f94a8610a4e588ee5671b7383cb9dfeac7903/Ja...
################################
#
# Close all running applications
#
################################
# Find all applications with osascript and process them into an array.
# Big thanks to William 'talkingmoose' Smith for this way of parsing lsappinfo
runningapps=($( /usr/bin/lsappinfo list | /usr/bin/grep -B 4 Foreground | /usr/bin/awk -F '\\) "|" ASN' 'NF > 1 { print $2 }' ))
# Process the new array of apps and gently kill them off one by one.
# Obviously we don't want to kill a few apps we don't routinely update.
for app ($runningapps)
do
[[ "$app" =~ ^(Finder|Progress|Google Chrome|Safari|Self Service|Terminal)$ ]] && continue
/usr/bin/pkill "$app"
done
fi
Posted on 07-28-2021 11:09 AM
I'm not sure if there's a better way to do this other than the osascript method. But I'm posting here in case anyone figures something out. I could use it myself at times.
Posted on 07-28-2021 12:04 PM
I might be interested in this as well. Have you tried to do a PPPC profile for this? I seem to have mixed results with them working as expected.
Posted on 07-30-2021 06:52 AM
After hours of not getting a correct PPPC profile and still getting the **bleep** pop up, I found another solution for this problem:
@franton together with @talkingmoose found a nice way to not use osascript to get (almost) the same result.
Almost, as in they are not using the pids but the process names. Which i guess doesn't make a big difference at the end.
Check the script here: https://github.com/franton/Mac-Patcher-and-Upgrader/blob/e78f94a8610a4e588ee5671b7383cb9dfeac7903/Ja...
################################
#
# Close all running applications
#
################################
# Find all applications with osascript and process them into an array.
# Big thanks to William 'talkingmoose' Smith for this way of parsing lsappinfo
runningapps=($( /usr/bin/lsappinfo list | /usr/bin/grep -B 4 Foreground | /usr/bin/awk -F '\\) "|" ASN' 'NF > 1 { print $2 }' ))
# Process the new array of apps and gently kill them off one by one.
# Obviously we don't want to kill a few apps we don't routinely update.
for app ($runningapps)
do
[[ "$app" =~ ^(Finder|Progress|Google Chrome|Safari|Self Service|Terminal)$ ]] && continue
/usr/bin/pkill "$app"
done
fi
Posted on 07-30-2021 08:32 AM
Hi,
Yeah this one is all @talkingmoose 😉
07-30-2021 09:22 AM - edited 07-30-2021 09:23 AM
just noticed that in your comment your in front of the code you're still talking about osascript, which I guess you were using before. Good thing for me, that was the keyword how I found it 😄 So sometimes forgetting something can be a benefit 😄