applescript or shell script way to i. e. grep an applications “status” after i. e. killall -STOP it









up vote
1
down vote

favorite
1












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.










share|improve this question























  • 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















up vote
1
down vote

favorite
1












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.










share|improve this question























  • 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













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 22:18

























asked Nov 10 at 19:59









Laut3

63




63











  • 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

















  • 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
















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













1 Answer
1






active

oldest

votes

















up vote
0
down vote













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





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    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





    share|improve this answer


























      up vote
      0
      down vote













      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





      share|improve this answer
























        up vote
        0
        down vote










        up vote
        0
        down vote









        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





        share|improve this answer














        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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 12 at 0:51

























        answered Nov 12 at 0:35









        Laut3

        63




        63



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto