You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过AppleScript根据背景色点击Safari网页中的当前会议绿色标签?

Solution to Click Green Background Meeting Tab via AppleScript

Hey there! Let's fix that element targeting issue. Since all your meeting tabs share the same class name, we can leverage JavaScript (run via AppleScript) to loop through those elements, check their computed background color, and click the one with the green background.

Key Idea

Instead of relying on element index, we'll:

  1. Grab all elements with the target class name
  2. Loop through each element to check its actual displayed background color (using getComputedStyle to account for CSS-styled colors, not just inline styles)
  3. Click the element once we find the green one

Updated Code with the New Function

Here's how to add this functionality to your existing script:

to clickClassName(theClassName, elementnum)
    tell application "Safari"
        do JavaScript "document.getElementsByClassName('" & theClassName & "')[" & elementnum & "].click();" in document 1
    end tell
end clickClassName

-- New function to click the green background meeting tab
to clickGreenMeetingTab(targetClassName)
    tell application "Safari"
        do JavaScript "
            const tabs = document.getElementsByClassName('" & targetClassName & "');
            // Loop through each tab to check background color
            for (let i = 0; i < tabs.length; i++) {
                const computedStyle = window.getComputedStyle(tabs[i]);
                const bgColor = computedStyle.backgroundColor;
                // Adjust this color value to match your actual green background
                // Common green values: 'rgb(0, 128, 0)', '#008000', 'rgb(46, 204, 113)' etc.
                if (bgColor === 'rgb(0, 128, 0)') {
                    tabs[i].click();
                    break; // Stop looping once we find and click the green tab
                }
            }
        " in document 1
    end tell
end clickGreenMeetingTab

tell application "Safari"
    activate
    open location "https://myclass.lpu.in/"
    delay 5
    tell application "System Events" to tell process "Safari"
        keystroke "USERNAME"
        delay 0.2
        keystroke tab
        delay 0.2
        keystroke "PASSWORD"
        delay 1
        keystroke return
        delay 5
    end tell
end tell

clickClassName("btn stretched-link text-white w-100", 0)
-- Call the new function to click the green meeting tab
-- Replace the class name below with the actual class of your meeting tabs
clickGreenMeetingTab("your-meeting-tab-class-name")

Important Notes

  • Adjust the color value: You need to replace 'rgb(0, 128, 0)' with the exact computed background color of your green tab. To find this:
    1. Right-click the green tab in Safari and select "Inspect Element"
    2. In the DevTools, go to the "Computed" tab and look for "background-color"
    3. Copy the exact value (it might be in rgb(), rgba(), or hex format)
  • Replace the class name: Make sure your-meeting-tab-class-name is the correct class shared by all 5 meeting tabs (you mentioned they have the same class, so fill that in here)
  • Delay adjustments: If the page takes longer to load the meeting tabs, add a delay X before calling clickGreenMeetingTab() to ensure elements are fully loaded

内容的提问来源于stack exchange,提问作者Bharath Reddy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 11:03:15