如何用applescript改变空间

时间:2011-08-04 19:04:05

标签: applescript

我有以下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

2 个答案:

答案 0 :(得分:2)

这可能不会让你到任何地方,但你可以使用这个脚本循环遍历所有空格,直到你看到你正在定位的应用程序......

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

答案 1 :(得分:1)

set front_app to current application

tell application "Spotify"
   next track
end tell

tell front_app to activate