javascript - 如何以编程方式打开我从 Electron DesktopCapurer.getSources 获得的窗口

标签 javascript node.js macos electron

我正在使用 MAC;
嗨,我正在使用 DesktopCapturer 来获取我可以记录的所有窗口,并且在使用 getSources 方法之后,我得到了像

appIcon: null
display_id: ""
id: "window:2643:0"
name: "cast – preload.ts"
thumbnail: {toPNG: ƒ, toJPEG: ƒ, toBitmap: ƒ, getBitmap: ƒ, getScaleFactors: ƒ, …}
__proto__: Object
这是一个 WebStorm 应用程序。如何以编程方式打开这个将这个应用程序移动到桌面上。

最佳答案

大家好,我找到了使用applescripts的解决方案
首先你应该得到所有带有窗口标题的打开应用程序

set tmpList to {}
set windowTitles to {}
set visibleProcesses to {}
set visibleProcessesWithWindows to {}
set processNamesAndWindowTitles to {}
set processNamesAndWindowTitlesLists to {}
tell application "System Events"
    set visibleProcesses to name of (every process whose visible is true)
    repeat with processName in visibleProcesses
        if (count windows of process processName) is not 0 then
            set end of visibleProcessesWithWindows to processName
        end if
    end repeat
    repeat with processName in visibleProcessesWithWindows
        set end of windowTitles to (name of every window of process processName)
        set end of tmpList to (processName as list) & windowTitles
        set end of processNamesAndWindowTitles to tmpList
        set windowTitles to {}
        set tmpList to {}
    end repeat
end tell
repeat with aItem in processNamesAndWindowTitles
    set end of processNamesAndWindowTitlesLists to item 1 of aItem
end repeat
return processNamesAndWindowTitlesLists
比你应该通过标题找到你的应用程序名称作为回应
tell application "System Events" to tell process "${appName}"
   set frontmost to true
    windows where title contains "${name}"
    if result is not {} then perform action "AXRaise" of item 1 of result
end tell
做在最前面

关于javascript - 如何以编程方式打开我从 Electron DesktopCapurer.getSources 获得的窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66174580/

相关文章:

macos - 无法将maven项目导入IDEA 14

node.js - 在 cmd 和本地主机 "createError is not defined"上得到这个输出

javascript - 正则表达式 - 包含句点后的特定数字

python - 在 Python 中创建的文件夹具有完全读/写权限时,为什么我会得到 Errno 1 Operation not permitted?

javascript - 尝试在按钮单击时打开模式

node.js - 如何在一个 Express app.get() 中使用多个 res.render()

macos - 如何使用 Homebrew 安装的 SQLite 而不是默认的?

javascript - _.template lodash 中的 onClick

javascript - 如何在正则表达式中转义星号?

javascript - 本站如何打开新窗口