【问题标题】:Applescript Fullscreen app and arrange order in High SierraApplescript 全屏应用程序并在 High Sierra 中安排订单
【发布时间】:2018-01-10 23:12:27
【问题描述】:

您好,感谢您抽出宝贵时间提供帮助。

我在 AppleScript 方面的编码经验有限。我想做的是创建一个脚本,该脚本将打开,设置为全屏,然后安排我经常使用的几个应用程序。如果应用程序已经打开,我在脚本中添加了一些逻辑来帮助流程。但我遇到的问题是在 For Next 循环期间,当我尝试将应用程序设置为全屏时,应用程序日历未激活,然后我收到“系统事件出错:无法获取窗口进程“日历”的 1。索引无效。错误。这是因为日历窗口还没有被索引,但是如果我在“激活”之后延迟大约 1-2 秒,那么脚本通常会运行。但肯定有一种方法可以在脚本尝试运行 Fullscreen 行之前命令脚本对 Calendars 的窗口进行索引?我想删除延迟代码行,以便脚本可以运行得更快。谁能提供一些想法或解决方案?

set app1 to "Maps"
set app2 to "Safari"
set app3 to "Mail"
set app4 to "Calendar"
set app5 to "Contacts"

set thelist to {app1, app2, app3, app4, app5}

repeat with i in thelist
	if application i is running then		
		tell application i
			activate
			delay 0.5
		end tell
		tell application "System Events" to tell process i
			set value of attribute "AXFullScreen" of window 1 to true
		end tell
	else
	end if
end repeat

【问题讨论】:

    标签: applescript fullscreen


    【解决方案1】:

    应用程序完成启动后,Windows 可用。你得等一等。但您可以将其限制在必要的时间:

    不要等待固定的延迟,而是执行以下操作

    repeat
        try
            tell application "System Events" to tell process i
                    set value of attribute "AXFullScreen" of window 1 to true
                    exit repeat
             end tell
        end try
        delay 0.01
    end repeat
    

    这样,该方法会尝试直到它工作,然后退出。

    【讨论】:

    • 或者在set value 命令之前插入一个repeat while not (exists window 1) \n end repeat可能会更快一些,并使代码更整洁。不过,我还没有测试过。
    猜你喜欢
    • 2017-04-21
    • 2018-07-10
    • 1970-01-01
    • 2018-05-09
    • 2018-12-05
    • 2016-07-16
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    相关资源
    最近更新 更多