如何使用applescript更改空间

如何使用applescript更改空间,applescript,Applescript,我有以下applescript可以跳过spotify中的歌曲。如果在全屏应用程序位于最前面时调用脚本,则脚本完成后,应用程序将不可见。它将在一个不同的空间。有没有一种方法可以让最前面的应用程序通过applescript再次可见 set front_app to (path to frontmost application as Unicode text) tell application "Spotify" next track end tell tell application fr

我有以下applescript可以跳过spotify中的歌曲。如果在全屏应用程序位于最前面时调用脚本,则脚本完成后,应用程序将不可见。它将在一个不同的空间。有没有一种方法可以让最前面的应用程序通过applescript再次可见

set front_app to (path to frontmost application as Unicode text) tell application "Spotify" next track end tell tell application front_app to activate 将前端应用程序设置为(最前端应用程序的路径为Unicode文本) 告诉应用程序“Spotify” 下一轨道 结束语 告诉应用程序前端应用程序激活
这可能不会让您有任何进展,但您可以使用此脚本在所有空间中循环,直到您看到目标应用程序

set front_application to current application
tell application "Spotify" to next track
tell application "Finder" to set collapsed of front_application to false --makes sure the app isn't minimized
repeat
    tell application "System Events" to keystroke (ASCII character 29) using {control down}
    display dialog "Correct space?" buttons{"OK"} default button 1 giving up after 4 --don't click 'OK' if the current space isn't showing the target application
    if gave up of the result is false then exit repeat
end repeat

代码看起来好多了,但它的行为是一样的。如果front_应用程序是全屏应用程序,那么在脚本执行后它仍然不可见。@Kim:啊,好的。我没有安装Lion,因此无法检查全屏应用程序。顺便问一下,你是如何启动脚本的?例如,内置脚本菜单、Quicksilver、快速脚本或其他什么?我在想,也许是启动程序而不是脚本从前端应用程序中窃取了焦点而没有返回。再说一次,这可能只是Lion的全屏应用程序的一个问题。我从Alfred那里启动了这个脚本。我有下一首歌、上一首歌、暂停等的脚本。只要当前应用程序不是全屏应用程序,它就会像一个符咒一样工作。@kim:Odd。虽然这对苹果来说不是什么新鲜事,但它忘记了AppleScript的支持。但是,这样做如何:不获取应用程序,而是获取应用程序的前窗口,并告诉它在调用Spotify后激活?再说一次,我无法控制自己,但值得一试。或者,根据fireshadow的回答,您可以查看系统事件是否具有“当前空间”,并可能切换回该空间。也许吧?谢谢你的回答,但我正在寻找一种不引人注目的方式跳过一首歌,所以弹出一个对话框不是我想做的事。你可以告诉应用程序“系统事件”在<代码>重复<代码>循环之前键入代码53。可能重复
set front_application to current application
tell application "Spotify" to next track
tell application "Finder" to set collapsed of front_application to false --makes sure the app isn't minimized
repeat
    tell application "System Events" to keystroke (ASCII character 29) using {control down}
    display dialog "Correct space?" buttons{"OK"} default button 1 giving up after 4 --don't click 'OK' if the current space isn't showing the target application
    if gave up of the result is false then exit repeat
end repeat