omdf00
@omdf00 (うめさん)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

hammerspoonでアプリを指定したウィンドウサイズで起動させたい

解決したいこと

→hammerspoonでアプリを指定したウィンドウサイズで起動させるようにしたい

発生している問題・エラー

hammerspoonでアプリ起動とウィンドウサイズのコードにそれぞれ別のホットキーを割り当てていて、これを同時に実行できるコードを書こうとしているのですが、自分で調べてみてもどうも上手く行かないため、アドバイスを頂きたいです。

該当するソースコード

--Adobe Bridge 2021
--移動/サイズ変更: Adobe Bridge 2021(10, -1000, 1896, 967)
local YourKeyMap = hs.hotkey.modal.new()
local function appTitle()
   app = hs.application.frontmostApplication()
   if app ~= nil then
      return app:title()
   end
end
local function chooseKeyMap()
   if appTitle() == 'Adobe Bridge 2021' then
      print('Turning ON keybindings for: ' .. appTitle())
      YourKeyMap:enter()
   else
      print('Turnning OFF keybindings for: ' .. appTitle())
      YourKeyMap:exit()
   end
end
local function appWatcherFunction(appName, eventType, appObject)
   if (eventType == hs.application.watcher.activated) then
      chooseKeyMap()
   end
end
local prefix = {"ctrl","shift","alt"}
YourKeyMap:bind(prefix, "[", function()
--US規格なので、"キーの刻印が「@」 --> luaでは「[」と記述"
  local win = hs.window.focusedWindow()
  local f = win:frame()
    f.x = 10
    f.y = -1100
    f.w = 1896
    f.h = 1042
    win:setFrame(f)
end)
chooseKeyMap()
local appWatcher = hs.application.watcher.new(appWatcherFunction)
appWatcher:start()
----------------------------------
----------------------------------
--Adobe Bridge 2021.app起動
remap({"shift","ctrl"}, "r",function()
      hs.reload()
      hs.application.launchOrFocus("/Applications/Adobe Bridge 2021/Adobe Bridge 2021.app")
end)


自分で試したこと

karabiner elementsを使う方法も試したのですが、いずれも上手く行きませんでした。

試したjsonスクリプト:1 
  →アプリ起動は実行されるが、アクティブウィンドウリサイズの処理の方が早く実行される為、
   任意のアプリウィンドウのリサイズを実行できない
{
      "description": "sft+ctrl+r → launch + open_bracket+sft+ctrl+opt(Adobe Bridge 2021.app)",
      "extra_description":[
                   "sft+ctrl+r → launch + open_bracket+sft+ctrl+opt(Adobe Bridge 2021.app)"
                          ],
      "manipulators": [{ "type": "basic",
                         "from": { "key_code": "r",
                                   "modifiers": { "mandatory": [
                                                    "shift","control"  ]
                                                }
                                 },
                         "to": [{ "shell_command": "open -a '/Applications/Adobe Bridge 2021/Adobe Bridge 2021.app'"
                                },
                                { "key_code": "open_bracket",
                                  "modifiers":["shift","control","option"]
                                }
                               ]
                      }]
    },


試したjsonスクリプト:2 
  →アプリ起動は実行されるが、ウィンドウリサイズの動作が実行されない
{
          "description": "sft+ctrl+r → launch + open_bracket+sft+ctrl+opt(Adobe Bridge 2021.app)",
          "extra_description":[
                       "sft+ctrl+r → launch + open_bracket+sft+ctrl+opt(Adobe Bridge 2021.app)"
                              ],
          "manipulators": [{ "type": "basic",
                             "from": { "key_code": "r",
                                       "modifiers": { "mandatory": [
                                                        "shift","control"  ]
                                                    }
                                     },
                             "to": [{ "shell_command": "open -a '/Applications/Adobe Bridge 2021/Adobe Bridge 2021.app'"
                                    },
                                    { "shell_command": "osascript -e 'set bounds of front window to {1, 1, 1280, 600}'"
                                    }
                                   ]
                          }]
    },


試したjsonスクリプト:3 
  →こちらもウィンドウ リサイズの動作のみが実行されない
{
          "description": "sft+ctrl+r → launch + open_bracket+sft+ctrl+opt(Adobe Bridge 2021.app)",
          "extra_description":[
                       "sft+ctrl+r → launch + open_bracket+sft+ctrl+opt(Adobe Bridge 2021.app)"
                              ],
          "manipulators": [{ "type": "basic",
                             "from": { "key_code": "r",
                                       "modifiers": { "mandatory": [
                                                        "shift","control"  ]
                                                    }
                                     },
                             "to": [{ "shell_command": "open -a '/Applications/Adobe Bridge 2021/Adobe Bridge 2021.app'"
                                    },
                                    { "shell_command": "osascript -e set topWindow to item 1 of (every window whose focused is true)"
                                    },
                                    {  "shell_command": "osascript set size of topWindow to {1908, 1041}"}
                                   ]
                          }]
    },


試したjsonスクリプト:4 
  →アプリ起動も、アクティブウィンドウリサイズも実行されない
{
          "description": "sft+ctrl+r → launch + open_bracket+sft+ctrl+opt(Adobe Bridge 2021.app)",
          "extra_description":[
                       "sft+ctrl+r → launch + open_bracket+sft+ctrl+opt(Adobe Bridge 2021.app)"
                              ],
          "manipulators": [{ "type": "basic",
                             "from": { "key_code": "r",
                                       "modifiers": { "mandatory": [
                                                        "shift","control"  ]
                                                    }
                                     },
                             "to": [{ "shell_command": "open -a '/Applications/Adobe Bridge 2021/Adobe Bridge 2021.app'"
                                    }],
                             "to_delayed_action": { "shell_command": "osascript -e 'set bounds of front window to {1, 1, 1280, 600}'"
                                                  }
                          }]
        },

0

No Answers yet.

Your answer might help someone💌