{"id":967,"date":"2010-12-16T22:32:51","date_gmt":"2010-12-16T13:32:51","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=967"},"modified":"2010-12-17T15:57:37","modified_gmt":"2010-12-17T06:57:37","slug":"mac%e3%81%a7%e9%87%8d%e3%81%84%e3%82%a2%e3%83%97%e3%83%aa%e3%82%b1%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92%e5%8a%87%e7%9a%84%e3%81%ab%e8%bb%bd%e3%81%8f%e3%81%99%e3%82%8bpython%e3%82%b9%e3%82%af","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/967","title":{"rendered":"Mac\u3067\u91cd\u3044\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5287\u7684\u306b\u8efd\u304f\u3059\u308bPython\u30b9\u30af\u30ea\u30d7\u30c8"},"content":{"rendered":"<p>\u8a87\u5f35\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u306a\u3093\u305bSIGSTOP\u4f7f\u3063\u3061\u3083\u3063\u3066\u307e\u3059\u304b\u3089w \u5287\u85acw<\/p>\n<p>\u50d5\u306f\u30e1\u30a4\u30f3\u306eMac\u3067\u306f\u5e38\u6642\u30d6\u30e9\u30a6\u30b6\u30923\u3064\u7acb\u3061\u4e0a\u3052\u3066\u307e\u3059\u3002<br \/>\n\u7ba1\u7406\u7528\uff08\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u306a\u3093\u3084\u304b\u3093\u3084\u3059\u308b\u3084\u3064\uff09\u3068\u3057\u3066Firefox\u3092\u3001\u4e3b\u306b\u60c5\u5831\u53ce\u96c6\u7528\u3068\u3057\u3066\u3082\u3046\u4e00\u3064Firefox\u3092\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u7528\u3068\u3057\u3066Chrome\u3092\u4f7f\u3063\u3066\u307e\u3059\u3002<br \/>\n\u3053\u306e\u3046\u30612\u3064\u306eFirefox\u3067\u305d\u308c\u305e\u308c\u5e38\u306b50\u301c100\u30bf\u30d6\u3050\u3089\u3044\u3072\u3089\u304d\u3063\u3071\u306a\u3057\u306b\u3057\u3066\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u304c\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u3082CPU\u306b\u304b\u306a\u308a\u306e\u8ca0\u8377\u3092\u639b\u3051\u3066\u307e\u3059\u3002<br \/>\n\u91cd\u3059\u304e\u308b\u306e\u3067\u60c5\u5831\u53ce\u96c6\u7528\u306a\u3093\u304b\u306fFlash\u3068JavaScript\u3092\u30aa\u30d5\uff08Flashblock\u3068NoScript\u3092\u4f7f\u7528\uff09\u306b\u3057\u3066\u308b\u304f\u3089\u3044\u3067\u3059\u304c\u3001\u305d\u308c\u3067\u3082\u30a2\u30a4\u30c9\u30eb\u6642\u306eCPU\u4f7f\u7528\u7387\u306e\u4e0a\u4f4d\u4e8c\u3064\u306fFirefox\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u306a\u3093\u3068\u304b\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3057\u3066\u3001\u968f\u5206\u524d\u306bTwitter\u306e\u307b\u3046\u306b\u30b7\u30b0\u30ca\u30eb\u3067\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4e00\u6642\u505c\u6b62\u30fb\u518d\u958b\u3059\u308b\u65b9\u6cd5\u3092\u8f09\u305b\u307e\u3057\u305f\u304c\u3001<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nkillall -SIGSTOP firefox-bin\r\nkillall -SIGCONT firefox-bin\r\n<\/pre>\n<p>\u3044\u3061\u3044\u3061\u30b3\u30de\u30f3\u30c9\u6253\u3064\u306e\u3082\u3081\u3093\u3069\u304f\u3055\u3044\u3002\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5316\u3057\u3066\u30af\u30ea\u30c3\u30af\u3067\u6e08\u307e\u3059\u3068\u8a00\u3063\u3066\u3082\u30cd\u30a7\u3002<\/p>\n<p>\u305d\u3053\u3067\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u6700\u524d\u9762\u306b\u3042\u308b\u304b\u3069\u3046\u304b\u3092\u968f\u6642\u8abf\u3079\u3064\u3064\u3001\u3044\u3044\u611f\u3058\u3067SIGSTOP\u30fbSIGCONT\u3057\u305f\u3089\u697d\u3068\u3044\u3046\u304b\u610f\u8b58\u3059\u308b\u5fc5\u8981\u3059\u3089\u306a\u3044\u3088\u306d\u3068\u601d\u3044\u307e\u3057\u3066\u3001AppleScript\u3067\u5b9f\u73fe\u3067\u304d\u306a\u3044\u304b\u6a21\u7d22\u3057\u305f\u3053\u3068\u3082\u3042\u3063\u305f\u306e\u3067\u3059\u304c\u3001AppleScript\u306e\u3042\u307e\u308a\u306e\u5909\u614b\u8a00\u8a9e\u3063\u3077\u308a\u306b\u632b\u6298\u3002<\/p>\n<p>\u305d\u308c\u304b\u3089Firefox\u306e\u30bf\u30d6\u3092\u6574\u7406\u3057\u305f\u308a\u3057\u3066CPU\u4f7f\u7528\u7387\u304c\u30ac\u30de\u30f3\u3067\u304d\u308b\u30ec\u30d9\u30eb\u307e\u3067\u4e0b\u304c\u3063\u305f\u306e\u3067\u4eca\u307e\u3067\u5fd8\u308c\u3066\u305f\u3093\u3067\u3059\u304c\u3001Python\u304b\u3089AppleScript\u3068\u540c\u3058\u3088\u3046\u306a\u4e8b\u304c\u51fa\u6765\u308b\uff08AppleScript\u3092\u64cd\u4f5c\u3067\u304d\u308b\uff1f\uff09\u3068\u3044\u3046appscript\u3068\u3044\u3046\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u3042\u308b\u3053\u3068\u3092\u4eca\u65e5\u77e5\u308a\u307e\u3057\u3066\u3001\u3068\u308a\u3042\u3048\u305a\u5b9f\u88c5\u3057\u3066\u307f\u305f\u6b21\u7b2c\u3067\u3042\u308a\u307e\u3059\u3002<br \/>\nappscript\u306feasy_install\u3068\u304b\u3067\u7c21\u5358\u306b\u5165\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u3093\u306a\u611f\u3058\u3002appsl.py<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#!\/usr\/bin\/env python\r\n# -*- coding: utf-8 -*-\r\n\r\n'''\r\napplication sleeper\r\n'''\r\n\r\nimport os, sys, time\r\nfrom subprocess import Popen, PIPE\r\nfrom appscript import *\r\n\r\ninterval = 0.5\r\n\r\ndef main():\r\n\tprocess_name = sys.argv&#x5B;1]\r\n\tmy_filename = os.path.basename(__file__)\r\n\t\r\n\tps = Popen(&#x5B;'ps', 'x'], stdout = PIPE)\r\n\tgrep = Popen(&#x5B;'grep', process_name], stdin = ps.stdout, stdout = PIPE)\r\n\tresult = grep.communicate()&#x5B;0]\r\n\tprocs = &#x5B;]\r\n\tfor line in result.split('\\n'):\r\n\t\tif 'grep' not in line and my_filename not in line and process_name in line:\r\n\t\t\tpid = int(line.split()&#x5B;0])\r\n\t\t\tprocs.append(dict(pid = pid, app = app(pid = pid), cont = True))\r\n\t\r\n\ttry:\r\n\t\twhile True:\r\n\t\t\ttime.sleep(interval)\r\n\t\t\tfor proc in procs:\r\n\t\t\t\tos.system('\/bin\/kill -s SIGCONT %d' % proc&#x5B;'pid'])\r\n\t\t\t\tif proc&#x5B;'app'].frontmost.get():\r\n\t\t\t\t\t# frontmost\u306a\u3089\u505c\u6b62\u3057\u306a\u3044\r\n\t\t\t\t\tif not proc&#x5B;'cont']:\r\n\t\t\t\t\t\tproc&#x5B;'cont'] = True\r\n\t\t\t\t\t\tprint 'continue %s' % proc&#x5B;'pid']\r\n\t\t\t\telse:\r\n\t\t\t\t\t# frontmost\u3058\u3083\u306a\u3044\u306a\u3089\u505c\u6b62\r\n\t\t\t\t\tos.system('\/bin\/kill -s SIGSTOP %d' % proc&#x5B;'pid'])\r\n\t\t\t\t\tif proc&#x5B;'cont']:\r\n\t\t\t\t\t\tproc&#x5B;'cont'] = False\r\n\t\t\t\t\t\tprint 'stop %s' % proc&#x5B;'pid']\r\n\texcept KeyboardInterrupt, e:\r\n\t\tpass\r\n\tfinally:\r\n\t\t# \u7d42\u308f\u308b\u6642\u306f\u3059\u3079\u3066\u518d\u958b\u3057\u3066\u304a\u304f\r\n\t\tprint 'destructing...'\r\n\t\tfor proc in procs:\r\n\t\t\tos.system('\/bin\/kill -s SIGCONT %d' % proc&#x5B;'pid'])\r\n\t\t\tprint 'continue %s' % proc&#x5B;'pid']\r\n\t\t\r\nif __name__ == '__main__':\r\n\tmain()\r\n<\/pre>\n<p>Firefox\u5c02\u7528\u3058\u3083\u306a\u3044\u3093\u3067\u3068\u308a\u3042\u3048\u305a\u666e\u901a\u306e\u30a6\u30a4\u30f3\u30c9\u30a6\u3092\u6301\u3064\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306a\u3089\u306a\u3093\u3067\u3082\u4f7f\u3048\u308b\u304b\u3068\u3002<\/p>\n<p>\u4f7f\u3044\u65b9\u306f\u3053\u3093\u306a\u611f\u3058\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npython appsl.py firefox-bin\r\n<\/pre>\n<p>\u5f53\u7136\u306a\u304c\u3089\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u306e\u51e6\u7406\u304c\u91cd\u8981\u306a\u610f\u5473\u3092\u6301\u3064\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u4f7f\u3046\u3079\u304d\u3067\u306f\u306a\u3044\u3067\u3059\u3002<br \/>\n\u3042\u3068\u9577\u671f\u9593\u306e\u30c6\u30b9\u30c8\u306f\u884c\u3063\u3066\u306a\u3044\u3067\u3059\u3002<br \/>\n\u4ee5\u524dkillall\u30b3\u30de\u30f3\u30c9\u3060\u3051\u3067\u8a66\u3057\u3066\u307f\u305f\u3068\u304d\u306fSTOP\u3057\u305f\u307e\u307eMac\u81ea\u4f53\u3092\u9577\u6642\u9593\u30b9\u30ea\u30fc\u30d7\u3057\u5fa9\u5e30\u3059\u308b\u3068\u3001SystemUIServer\u306eCPU\u5229\u7528\u7387\u304c\u4e0a\u304c\u308a\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u5168\u4f53\u304c\u91cd\u304f\u306a\u308b\u3068\u3044\u3046\u73fe\u8c61\u3092\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u305d\u306e\u969bCONT\u3055\u305b\u308b\u3068\u6b63\u5e38\u306a\u72b6\u614b\u306b\u623b\u308b\u3053\u3068\u3082\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306f\u5bfe\u8c61\u304c\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u306e\u5834\u5408\u3067\u30820.5\u79d2\u3054\u3068\u306bCONT\u2192STOP\u3092\u3084\u3063\u3066\u307e\u3059\u306e\u3067\u3001\u540c\u3058\u3088\u3046\u306a\u554f\u984c\u304c\u8d77\u304d\u3066\u3082\u3042\u307e\u308a\u5f71\u97ff\u306f\u306a\u3044\u304b\u306a\u306a\u3093\u3066\u601d\u3063\u3066\u307e\u3059\u3002<\/p>\n<p>\u8868\u793a\u4e2d\u306e\u30bf\u30d6\u4ee5\u5916\u306f\u51e6\u7406\u3092\u6b62\u3081\u308b\u3001\u3068\u3044\u3046\u6a5f\u80fd\u304cFirefox\u306b\u3042\u308b\u3068\u4e00\u756a\u3044\u3044\u3093\u3067\u3059\u304c\u3001\u4ee5\u524dFirefox\u306e\u3048\u3089\u3044\u4eba\u304c\u300c\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u306e\u30bf\u30d6\u306eGmail\u3067\u65b0\u7740\u30e1\u30fc\u30eb\u306e\u78ba\u8a8d\u304c\u51fa\u6765\u306a\u304f\u306a\u308b\u300d\u7684\u306a\u4e8b\u3092\u7406\u7531\u306b\u5b9f\u88c5\u3057\u306a\u3044\u3068\u3044\u3046\u5642\u3092\u805e\u3044\u305f\u3053\u3068\u304c\u3042\u308b\u306e\u3067\u3001\u671b\u307f\u306f\u8584\u3044\u3067\u3059\u3002<br \/>\n\u305f\u3060Chrome\u3068\u540c\u3058\u3088\u3046\u306b\u3001\u30bf\u30d6\u3054\u3068\u306b\u30d7\u30ed\u30bb\u30b9\u3092\u5206\u3051\u308b\u3088\u3046\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3082\u307c\u3061\u307c\u3061\u9032\u3093\u3067\u308b\u307f\u305f\u3044\u306a\u306e\u3067\u3001\u305d\u3063\u3061\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3089\u300c\u8868\u793a\u4e2d\u306e\u30bf\u30d6\u4ee5\u5916\u306f\u51e6\u7406\u3092\u6b62\u3081\u308b\u300d\u3068\u3044\u3046\u30a2\u30c9\u30aa\u30f3\u3082\u51fa\u3066\u304f\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3044\u3064\u306b\u306a\u308b\u304b\u306f\u5206\u304b\u308a\u307e\u305b\u3093\u304c\u3002<br \/>\n\u3068\u3044\u3046\u304b\u6700\u521d\u304b\u3089\u30bf\u30d6\u3054\u3068\u306b\u30d7\u30ed\u30bb\u30b9\u304c\u5206\u304b\u308c\u3066\u308bChrome\u306b\u306a\u3089\u3082\u3046\u3042\u308b\u304b\u3082\u3002<br \/>\n\u3067\u3082\u3001Firefox\u306e\u300c\u30c4\u30ea\u30fc\u578b\u30bf\u30d6\u300d\u30a2\u30c9\u30aa\u30f3\u306b\u5339\u6575\u3059\u308b\u304f\u3089\u3044\u306e\u7e26\u30bf\u30d6\u304c\u4f7f\u3048\u306a\u3044\u3068\u30e1\u30a4\u30f3\u3067\u4f7f\u3046\u6c17\u306b\u306f\u306a\u3089\u306a\u3044\u3067\u3059\u3002<br \/>\n\uff08Windows\u7248\u3067\u306a\u3089\u7e26\u30bf\u30d6\u304c\u4f7f\u3048\u308b\u4e8b\u3092\u3061\u3087\u3063\u3068\u524d\u306b\u78ba\u8a8d\u3057\u3066\u307e\u3059\u304c\u3001\u898b\u305f\u76ee\u3082\u4f7f\u3044\u52dd\u624b\u3082\u307e\u3060\u307e\u3060\u3046\u3093\u3053\u3067\u3059\u3002\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8a87\u5f35\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u306a\u3093\u305bSIGSTOP\u4f7f\u3063\u3061\u3083\u3063\u3066\u307e\u3059\u304b\u3089w \u5287\u85acw<\/p>\n<p>\u50d5\u306f\u30e1\u30a4\u30f3\u306eMac\u3067\u306f\u5e38\u6642\u30d6\u30e9\u30a6\u30b6\u30923\u3064\u7acb\u3061\u4e0a\u3052\u3066\u307e\u3059\u3002<br \/>\n\u7ba1\u7406\u7528\uff08\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u306a\u3093\u3084\u304b\u3093\u3084\u3059\u308b\u3084\u3064\uff09\u3068\u3057\u3066Firefox\u3092\u3001\u4e3b\u306b\u60c5\u5831\u53ce\u96c6\u7528\u3068\u3057\u3066\u3082\u3046\u4e00\u3064Firefox\u3092\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u7528\u3068\u3057\u3066Chrome\u3092\u4f7f\u3063\u3066\u307e\u3059\u3002<br \/>\n\u3053\u306e\u3046\u30612\u3064\u306eFirefox\u3067\u305d\u308c\u305e\u308c\u5e38\u306b50\u301c100\u30bf\u30d6\u3050\u3089\u3044\u3072\u3089\u304d\u3063\u3071\u306a\u3057\u306b\u3057\u3066\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u304c\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u3082CPU\u306b\u304b\u306a\u308a\u306e\u8ca0\u8377\u3092\u639b\u3051\u3066\u307e\u3059\u3002<br \/>\n\u91cd\u3059\u304e\u308b\u306e\u3067\u60c5\u5831\u53ce\u96c6\u7528\u306a\u3093\u304b\u306fFlash\u3068JavaScript\u3092\u30aa\u30d5\uff08Flashblock\u3068NoScript\u3092\u4f7f\u7528\uff09\u306b\u3057\u3066\u308b\u304f\u3089\u3044\u3067\u3059\u304c\u3001\u305d\u308c\u3067\u3082\u30a2\u30a4\u30c9\u30eb\u6642\u306eCPU\u4f7f\u7528\u7387\u306e\u4e0a\u4f4d\u4e8c\u3064\u306fFirefox\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u306a\u3093\u3068\u304b\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3057\u3066\u3001\u968f\u5206\u524d\u306bTwitter\u306e\u307b\u3046\u306b\u30b7\u30b0\u30ca\u30eb\u3067\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4e00\u6642\u505c\u6b62\u30fb\u518d\u958b\u3059\u308b\u65b9\u6cd5\u3092\u8f09\u305b\u307e\u3057\u305f\u304c\u3001<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nkillall -SIGSTOP firefox-bin\r\nkillall -SIGCONT firefox-bin\r\n<\/pre>\n<p>\u3044\u3061\u3044\u3061\u30b3\u30de\u30f3\u30c9\u6253\u3064\u306e\u3082\u3081\u3093\u3069\u304f\u3055\u3044\u3002\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5316\u3057\u3066\u30af\u30ea\u30c3\u30af\u3067\u6e08\u307e\u3059\u3068\u8a00\u3063\u3066\u3082\u30cd\u30a7\u3002<\/p>\n<p>\u305d\u3053\u3067\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u6700\u524d\u9762\u306b\u3042\u308b\u304b\u3069\u3046\u304b\u3092\u968f\u6642\u8abf\u3079\u3064\u3064\u3001\u3044\u3044\u611f\u3058\u3067SIGSTOP\u30fbSIGCONT\u3057\u305f\u3089\u697d\u3068\u3044\u3046\u304b\u610f\u8b58\u3059\u308b\u5fc5\u8981\u3059\u3089\u306a\u3044\u3088\u306d\u3068\u601d\u3044\u307e\u3057\u3066\u3001AppleScript\u3067\u5b9f\u73fe\u3067\u304d\u306a\u3044\u304b\u6a21\u7d22\u3057\u305f\u3053\u3068\u3082\u3042\u3063\u305f\u306e\u3067\u3059\u304c\u3001AppleScript\u306e\u3042\u307e\u308a\u306e\u5909\u614b\u8a00\u8a9e\u3063\u3077\u308a\u306b\u632b\u6298\u3002<\/p>\n<p>\u305d\u308c\u304b\u3089Firefox\u306e\u30bf\u30d6\u3092\u6574\u7406\u3057\u305f\u308a\u3057\u3066CPU\u4f7f\u7528\u7387\u304c\u30ac\u30de\u30f3\u3067\u304d\u308b\u30ec\u30d9\u30eb\u307e\u3067\u4e0b\u304c\u3063\u305f\u306e\u3067\u4eca\u307e\u3067\u5fd8\u308c\u3066\u305f\u3093\u3067\u3059\u304c\u3001Python\u304b\u3089AppleScript\u3068\u540c\u3058\u3088\u3046\u306a\u4e8b\u304c\u51fa\u6765\u308b\uff08AppleScript\u3092\u64cd\u4f5c\u3067\u304d\u308b\uff1f\uff09\u3068\u3044\u3046appscript\u3068\u3044\u3046\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u3042\u308b\u3053\u3068\u3092\u4eca\u65e5\u77e5\u308a\u307e\u3057\u3066\u3001\u3068\u308a\u3042\u3048\u305a\u5b9f\u88c5\u3057\u3066\u307f\u305f\u6b21\u7b2c\u3067\u3042\u308a\u307e\u3059\u3002<br \/>\nappscript\u306feasy_install\u3068\u304b\u3067\u7c21\u5358\u306b\u5165\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u3093\u306a\u611f\u3058\u3002appsl.py<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#!\/usr\/bin\/env python\r\n# -*- coding: utf-8 -*-\r\n\r\n'''\r\napplication sleeper\r\n'''\r\n\r\nimport os, sys, time\r\nfrom subprocess import Popen, PIPE\r\nfrom appscript import *\r\n\r\ninterval = 0.5\r\n\r\ndef main():\r\n\tprocess_name = sys.argv&#x5B;1]\r\n\tmy_filename = os.path.basename(__file__)\r\n\t\r\n\tps = Popen(&#x5B;'ps', 'x'], stdout = PIPE)\r\n\tgrep = Popen(&#x5B;'grep', process_name], stdin = ps.stdout, stdout = PIPE)\r\n\tresult = grep.communicate()&#x5B;0]\r\n\tprocs = &#x5B;]\r\n\tfor line in result.split('\\n'):\r\n\t\tif 'grep' not in line and my_filename not in line and process_name in line:\r\n\t\t\tpid = int(line.split()&#x5B;0])\r\n\t\t\tprocs.append(dict(pid = pid, app = app(pid = pid), cont = True))\r\n\t\r\n\ttry:\r\n\t\twhile True:\r\n\t\t\ttime.sleep(interval)\r\n\t\t\tfor proc in procs:\r\n\t\t\t\tos.system('\/bin\/kill -s SIGCONT %d' % proc&#x5B;'pid'])\r\n\t\t\t\tif proc&#x5B;'app'].frontmost.get():\r\n\t\t\t\t\t# frontmost\u306a\u3089\u505c\u6b62\u3057\u306a\u3044\r\n\t\t\t\t\tif not proc&#x5B;'cont']:\r\n\t\t\t\t\t\tproc&#x5B;'cont'] = True\r\n\t\t\t\t\t\tprint 'continue %s' % proc&#x5B;'pid']\r\n\t\t\t\telse:\r\n\t\t\t\t\t# frontmost\u3058\u3083\u306a\u3044\u306a\u3089\u505c\u6b62\r\n\t\t\t\t\tos.system('\/bin\/kill -s SIGSTOP %d' % proc&#x5B;'pid'])\r\n\t\t\t\t\tif proc&#x5B;'cont']:\r\n\t\t\t\t\t\tproc&#x5B;'cont'] = False\r\n\t\t\t\t\t\tprint 'stop %s' % proc&#x5B;'pid']\r\n\texcept KeyboardInterrupt, e:\r\n\t\tpass\r\n\tfinally:\r\n\t\t# \u7d42\u308f\u308b\u6642\u306f\u3059\u3079\u3066\u518d\u958b\u3057\u3066\u304a\u304f\r\n\t\tprint 'destructing...'\r\n\t\tfor proc in procs:\r\n\t\t\tos.system('\/bin\/kill -s SIGCONT %d' % proc&#x5B;'pid'])\r\n\t\t\tprint 'continue %s' % proc&#x5B;'pid']\r\n\t\t\r\nif __name__ == '__main__':\r\n\tmain()\r\n<\/pre>\n<p>Firefox\u5c02\u7528\u3058\u3083\u306a\u3044\u3093\u3067\u3068\u308a\u3042\u3048\u305a\u666e\u901a\u306e\u30a6\u30a4\u30f3\u30c9\u30a6\u3092\u6301\u3064\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306a\u3089\u306a\u3093\u3067\u3082\u4f7f\u3048\u308b\u304b\u3068\u3002<\/p>\n<p>\u4f7f\u3044\u65b9\u306f\u3053\u3093\u306a\u611f\u3058\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npython appsl.py firefox-bin\r\n<\/pre>\n<p>\u5f53\u7136\u306a\u304c\u3089\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u306e\u51e6\u7406\u304c\u91cd\u8981\u306a\u610f\u5473\u3092\u6301\u3064\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u4f7f\u3046\u3079\u304d\u3067\u306f\u306a\u3044\u3067\u3059\u3002<br \/>\n\u3042\u3068\u9577\u671f\u9593\u306e\u30c6\u30b9\u30c8\u306f\u884c\u3063\u3066\u306a\u3044\u3067\u3059\u3002<br \/>\n\u4ee5\u524dkillall\u30b3\u30de\u30f3\u30c9\u3060\u3051\u3067\u8a66\u3057\u3066\u307f\u305f\u3068\u304d\u306fSTOP\u3057\u305f\u307e\u307eMac\u81ea\u4f53\u3092\u9577\u6642\u9593\u30b9\u30ea\u30fc\u30d7\u3057\u5fa9\u5e30\u3059\u308b\u3068\u3001SystemUIServer\u306eCPU\u5229\u7528\u7387\u304c\u4e0a\u304c\u308a\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u5168\u4f53\u304c\u91cd\u304f\u306a\u308b\u3068\u3044\u3046\u73fe\u8c61\u3092\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u305d\u306e\u969bCONT\u3055\u305b\u308b\u3068\u6b63\u5e38\u306a\u72b6\u614b\u306b\u623b\u308b\u3053\u3068\u3082\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306f\u5bfe\u8c61\u304c\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u306e\u5834\u5408\u3067\u30820.5\u79d2\u3054\u3068\u306bCONT\u2192STOP\u3092\u3084\u3063\u3066\u307e\u3059\u306e\u3067\u3001\u540c\u3058\u3088\u3046\u306a\u554f\u984c\u304c\u8d77\u304d\u3066\u3082\u3042\u307e\u308a\u5f71\u97ff\u306f\u306a\u3044\u304b\u306a\u306a\u3093\u3066\u601d\u3063\u3066\u307e\u3059\u3002<\/p>\n<p>\u8868\u793a\u4e2d\u306e\u30bf\u30d6\u4ee5\u5916\u306f\u51e6\u7406\u3092\u6b62\u3081\u308b\u3001\u3068\u3044\u3046\u6a5f\u80fd\u304cFirefox\u306b\u3042\u308b\u3068\u4e00\u756a\u3044\u3044\u3093\u3067\u3059\u304c\u3001\u4ee5\u524dFirefox\u306e\u3048\u3089\u3044\u4eba\u304c\u300c\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u306e\u30bf\u30d6\u306eGmail\u3067\u65b0\u7740\u30e1\u30fc\u30eb\u306e\u78ba\u8a8d\u304c\u51fa\u6765\u306a\u304f\u306a\u308b\u300d\u7684\u306a\u4e8b\u3092\u7406\u7531\u306b\u5b9f\u88c5\u3057\u306a\u3044\u3068\u3044\u3046\u5642\u3092\u805e\u3044\u305f\u3053\u3068\u304c\u3042\u308b\u306e\u3067\u3001\u671b\u307f\u306f\u8584\u3044\u3067\u3059\u3002<br \/>\n\u305f\u3060Chrome\u3068\u540c\u3058\u3088\u3046\u306b\u3001\u30bf\u30d6\u3054\u3068\u306b\u30d7\u30ed\u30bb\u30b9\u3092\u5206\u3051\u308b\u3088\u3046\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3082\u307c\u3061\u307c\u3061\u9032\u3093\u3067\u308b\u307f\u305f\u3044\u306a\u306e\u3067\u3001\u305d\u3063\u3061\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3089\u300c\u8868\u793a\u4e2d\u306e\u30bf\u30d6\u4ee5\u5916\u306f\u51e6\u7406\u3092\u6b62\u3081\u308b\u300d\u3068\u3044\u3046\u30a2\u30c9\u30aa\u30f3\u3082\u51fa\u3066\u304f\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3044\u3064\u306b\u306a\u308b\u304b\u306f\u5206\u304b\u308a\u307e\u305b\u3093\u304c\u3002<br \/>\n\u3068\u3044\u3046\u304b\u6700\u521d\u304b\u3089\u30bf\u30d6\u3054\u3068\u306b\u30d7\u30ed\u30bb\u30b9\u304c\u5206\u304b\u308c\u3066\u308bChrome\u306b\u306a\u3089\u3082\u3046\u3042\u308b\u304b\u3082\u3002<br \/>\n\u3067\u3082\u3001Firefox\u306e\u300c\u30c4\u30ea\u30fc\u578b\u30bf\u30d6\u300d\u30a2\u30c9\u30aa\u30f3\u306b\u5339\u6575\u3059\u308b\u304f\u3089\u3044\u306e\u7e26\u30bf\u30d6\u304c\u4f7f\u3048\u306a\u3044\u3068\u30e1\u30a4\u30f3\u3067\u4f7f\u3046\u6c17\u306b\u306f\u306a\u3089\u306a\u3044\u3067\u3059\u3002<br \/>\n\uff08Windows\u7248\u3067\u306a\u3089\u7e26\u30bf\u30d6\u304c\u4f7f\u3048\u308b\u4e8b\u3092\u3061\u3087\u3063\u3068\u524d\u306b\u78ba\u8a8d\u3057\u3066\u307e\u3059\u304c\u3001\u898b\u305f\u76ee\u3082\u4f7f\u3044\u52dd\u624b\u3082\u307e\u3060\u307e\u3060\u3046\u3093\u3053\u3067\u3059\u3002\uff09<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[60],"class_list":["post-967","post","type-post","status-publish","format-standard","hentry","category-tech","tag-python"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/comments?post=967"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/967\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}