applescript or shell script way to i. e. grep an applications “status” after i. e. killall -STOP it
up vote
1
down vote
favorite
If I pause an applications by
killall -STOP
it, is there a way to read this "status" for later use? I want to write a short script that checks if the application is already stopped and if so start it again via
killall -CONT
and if not I want to be able to pause it.
macos shell applescript kill-process
add a comment |
up vote
1
down vote
favorite
If I pause an applications by
killall -STOP
it, is there a way to read this "status" for later use? I want to write a short script that checks if the application is already stopped and if so start it again via
killall -CONT
and if not I want to be able to pause it.
macos shell applescript kill-process
Use something likekillall -d
orpgrep
to discover the process IDs of the target processes, then useps
to discover the state of the processes that have those IDs.ps
will show the state of a process as the letter "T" if the process is stopped. Runps -j
manually to see an example of the state (in the STAT column) being shown along with a bunch of other stuff. For scripting it's easier to tellps
to show only the state for a given<pid>
by runningps -o state= -p <pid>
.
– ottomeister
Nov 11 at 20:16
I made a script out of your suggestions. It works, thx a lot.
– Laut3
Nov 12 at 0:36
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
If I pause an applications by
killall -STOP
it, is there a way to read this "status" for later use? I want to write a short script that checks if the application is already stopped and if so start it again via
killall -CONT
and if not I want to be able to pause it.
macos shell applescript kill-process
If I pause an applications by
killall -STOP
it, is there a way to read this "status" for later use? I want to write a short script that checks if the application is already stopped and if so start it again via
killall -CONT
and if not I want to be able to pause it.
macos shell applescript kill-process
macos shell applescript kill-process
edited Nov 10 at 22:18
asked Nov 10 at 19:59
Laut3
64
64
Use something likekillall -d
orpgrep
to discover the process IDs of the target processes, then useps
to discover the state of the processes that have those IDs.ps
will show the state of a process as the letter "T" if the process is stopped. Runps -j
manually to see an example of the state (in the STAT column) being shown along with a bunch of other stuff. For scripting it's easier to tellps
to show only the state for a given<pid>
by runningps -o state= -p <pid>
.
– ottomeister
Nov 11 at 20:16
I made a script out of your suggestions. It works, thx a lot.
– Laut3
Nov 12 at 0:36
add a comment |
Use something likekillall -d
orpgrep
to discover the process IDs of the target processes, then useps
to discover the state of the processes that have those IDs.ps
will show the state of a process as the letter "T" if the process is stopped. Runps -j
manually to see an example of the state (in the STAT column) being shown along with a bunch of other stuff. For scripting it's easier to tellps
to show only the state for a given<pid>
by runningps -o state= -p <pid>
.
– ottomeister
Nov 11 at 20:16
I made a script out of your suggestions. It works, thx a lot.
– Laut3
Nov 12 at 0:36
Use something like
killall -d
or pgrep
to discover the process IDs of the target processes, then use ps
to discover the state of the processes that have those IDs. ps
will show the state of a process as the letter "T" if the process is stopped. Run ps -j
manually to see an example of the state (in the STAT column) being shown along with a bunch of other stuff. For scripting it's easier to tell ps
to show only the state for a given <pid>
by running ps -o state= -p <pid>
.– ottomeister
Nov 11 at 20:16
Use something like
killall -d
or pgrep
to discover the process IDs of the target processes, then use ps
to discover the state of the processes that have those IDs. ps
will show the state of a process as the letter "T" if the process is stopped. Run ps -j
manually to see an example of the state (in the STAT column) being shown along with a bunch of other stuff. For scripting it's easier to tell ps
to show only the state for a given <pid>
by running ps -o state= -p <pid>
.– ottomeister
Nov 11 at 20:16
I made a script out of your suggestions. It works, thx a lot.
– Laut3
Nov 12 at 0:36
I made a script out of your suggestions. It works, thx a lot.
– Laut3
Nov 12 at 0:36
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
It works like that. With this script you are able to pause and unpause a program.
set shellOutput1 to do shell script "PROCESSNAME='<name of the process>'; GREPPID=$(pgrep $PROCESSNAME); if [ -z $GREPPID ]; then echo '1'; else echo '2'; fi; exit 0"
if shellOutput1 contains "2" then
tell application "Finder"
set visible of process "<name of the process>" to false
end tell
end if
set notificationName to "<program name>"
set shellOutput2 to do shell script "PROCESSNAME='<name of the process>'; GREPPID=$(pgrep $PROCESSNAME); if [ -z $GREPPID ]; then echo '3'; exit 0; else PSSTATUS=$(ps -o state= -p $GREPPID); if [ $PSSTATUS == 'T' ]; then killall -CONT $PROCESSNAME; echo '1'; else killall -STOP $PROCESSNAME; echo '2'; fi; fi; exit 0"
if shellOutput2 contains "1" then
tell application "Finder"
set visible of process "<name of the process>" to true
end tell
display notification notificationName & " wieder gestartet!" sound name "default"
else if shellOutput2 contains "2" then
display notification notificationName & " angehalten!" sound name "default"
else if shellOutput2 contains "3" then
display notification notificationName & " läuft nicht!" sound name "default"
end if
return shellOutput2
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
It works like that. With this script you are able to pause and unpause a program.
set shellOutput1 to do shell script "PROCESSNAME='<name of the process>'; GREPPID=$(pgrep $PROCESSNAME); if [ -z $GREPPID ]; then echo '1'; else echo '2'; fi; exit 0"
if shellOutput1 contains "2" then
tell application "Finder"
set visible of process "<name of the process>" to false
end tell
end if
set notificationName to "<program name>"
set shellOutput2 to do shell script "PROCESSNAME='<name of the process>'; GREPPID=$(pgrep $PROCESSNAME); if [ -z $GREPPID ]; then echo '3'; exit 0; else PSSTATUS=$(ps -o state= -p $GREPPID); if [ $PSSTATUS == 'T' ]; then killall -CONT $PROCESSNAME; echo '1'; else killall -STOP $PROCESSNAME; echo '2'; fi; fi; exit 0"
if shellOutput2 contains "1" then
tell application "Finder"
set visible of process "<name of the process>" to true
end tell
display notification notificationName & " wieder gestartet!" sound name "default"
else if shellOutput2 contains "2" then
display notification notificationName & " angehalten!" sound name "default"
else if shellOutput2 contains "3" then
display notification notificationName & " läuft nicht!" sound name "default"
end if
return shellOutput2
add a comment |
up vote
0
down vote
accepted
It works like that. With this script you are able to pause and unpause a program.
set shellOutput1 to do shell script "PROCESSNAME='<name of the process>'; GREPPID=$(pgrep $PROCESSNAME); if [ -z $GREPPID ]; then echo '1'; else echo '2'; fi; exit 0"
if shellOutput1 contains "2" then
tell application "Finder"
set visible of process "<name of the process>" to false
end tell
end if
set notificationName to "<program name>"
set shellOutput2 to do shell script "PROCESSNAME='<name of the process>'; GREPPID=$(pgrep $PROCESSNAME); if [ -z $GREPPID ]; then echo '3'; exit 0; else PSSTATUS=$(ps -o state= -p $GREPPID); if [ $PSSTATUS == 'T' ]; then killall -CONT $PROCESSNAME; echo '1'; else killall -STOP $PROCESSNAME; echo '2'; fi; fi; exit 0"
if shellOutput2 contains "1" then
tell application "Finder"
set visible of process "<name of the process>" to true
end tell
display notification notificationName & " wieder gestartet!" sound name "default"
else if shellOutput2 contains "2" then
display notification notificationName & " angehalten!" sound name "default"
else if shellOutput2 contains "3" then
display notification notificationName & " läuft nicht!" sound name "default"
end if
return shellOutput2
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
It works like that. With this script you are able to pause and unpause a program.
set shellOutput1 to do shell script "PROCESSNAME='<name of the process>'; GREPPID=$(pgrep $PROCESSNAME); if [ -z $GREPPID ]; then echo '1'; else echo '2'; fi; exit 0"
if shellOutput1 contains "2" then
tell application "Finder"
set visible of process "<name of the process>" to false
end tell
end if
set notificationName to "<program name>"
set shellOutput2 to do shell script "PROCESSNAME='<name of the process>'; GREPPID=$(pgrep $PROCESSNAME); if [ -z $GREPPID ]; then echo '3'; exit 0; else PSSTATUS=$(ps -o state= -p $GREPPID); if [ $PSSTATUS == 'T' ]; then killall -CONT $PROCESSNAME; echo '1'; else killall -STOP $PROCESSNAME; echo '2'; fi; fi; exit 0"
if shellOutput2 contains "1" then
tell application "Finder"
set visible of process "<name of the process>" to true
end tell
display notification notificationName & " wieder gestartet!" sound name "default"
else if shellOutput2 contains "2" then
display notification notificationName & " angehalten!" sound name "default"
else if shellOutput2 contains "3" then
display notification notificationName & " läuft nicht!" sound name "default"
end if
return shellOutput2
It works like that. With this script you are able to pause and unpause a program.
set shellOutput1 to do shell script "PROCESSNAME='<name of the process>'; GREPPID=$(pgrep $PROCESSNAME); if [ -z $GREPPID ]; then echo '1'; else echo '2'; fi; exit 0"
if shellOutput1 contains "2" then
tell application "Finder"
set visible of process "<name of the process>" to false
end tell
end if
set notificationName to "<program name>"
set shellOutput2 to do shell script "PROCESSNAME='<name of the process>'; GREPPID=$(pgrep $PROCESSNAME); if [ -z $GREPPID ]; then echo '3'; exit 0; else PSSTATUS=$(ps -o state= -p $GREPPID); if [ $PSSTATUS == 'T' ]; then killall -CONT $PROCESSNAME; echo '1'; else killall -STOP $PROCESSNAME; echo '2'; fi; fi; exit 0"
if shellOutput2 contains "1" then
tell application "Finder"
set visible of process "<name of the process>" to true
end tell
display notification notificationName & " wieder gestartet!" sound name "default"
else if shellOutput2 contains "2" then
display notification notificationName & " angehalten!" sound name "default"
else if shellOutput2 contains "3" then
display notification notificationName & " läuft nicht!" sound name "default"
end if
return shellOutput2
edited Nov 12 at 0:51
answered Nov 12 at 0:35
Laut3
64
64
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242884%2fapplescript-or-shell-script-way-to-i-e-grep-an-applications-status-after-i%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Use something like
killall -d
orpgrep
to discover the process IDs of the target processes, then useps
to discover the state of the processes that have those IDs.ps
will show the state of a process as the letter "T" if the process is stopped. Runps -j
manually to see an example of the state (in the STAT column) being shown along with a bunch of other stuff. For scripting it's easier to tellps
to show only the state for a given<pid>
by runningps -o state= -p <pid>
.– ottomeister
Nov 11 at 20:16
I made a script out of your suggestions. It works, thx a lot.
– Laut3
Nov 12 at 0:36