Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1005697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:20:22+00:00 2026-05-16T08:20:22+00:00

I am trying this simple GUI script to open a new window of Safari:

  • 0

I am trying this simple GUI script to open a new window of Safari:

tell application "Safari"
    activate
end tell

tell application "System Events"
    tell process "Safari"
        try
            tell menu bar 1
                tell menu bar item 3
                    click menu item 1
                end tell
            end tell
        on error theError
            display dialog ("An error occurred while performing requested action" & theError) buttons "OK" default button "OK"
        end try
    end tell
end tell

but it is giving this error message:

Expected end of line but found “””

Can anyone suggest me where I may be wrong?

Thanks,

Miraaj

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:20:23+00:00Added an answer on May 16, 2026 at 8:20 am

    Wow, that was weird. Your script broke AppleScript Editor. After running your script and it not working… I tried to recompile the script and then the error you posted starting showing up. So somehow your code caused AppleScript editor to break and thus the error. I had to quit and relaunch AppleScript Editor to get it working again.

    I used the application UI Browser and found the problem. Your reference to the menu item was wrong. There’s an extra menu in there that we can’t see… and you didn’t reference that extra menu. This is the problem with gui scripting. And even if a gui script works it may break at some future date as an application is updated. As such avoid gui scripting if at all possible.

    Anyway, here’s what your code should look like…

    tell application "Safari"
        activate
    end tell
    
    tell application "System Events"
        tell process "Safari"
            try
                tell menu bar 1
                    tell menu bar item 3
                        click menu item 1 of menu 1
                    end tell
                end tell
            on error theError
                display dialog ("An error occurred while performing requested action " & theError) buttons "OK" default button "OK"
            end try
        end tell
    end tell
    

    EDIT:
    As I mentioned in my comment below, if you can’t find a native command from an application’s dictionary, the next most reliable method is using keyboard shortcuts. Most menu items have them. For example, if I wanted to open a new tab in a window that menu item has the keyboard shortcut command-t. So we can use that like this. Note there is a native command to open a new tab without using keystrokes, I’m just showing this as an example.

    tell application "Safari" to activate
    tell application "System Events"
        keystroke "t" using command down
    end tell
    end
    

    Keyboard commands don’t usually change between application updates whereas gui commands often do because programmers redesign their interface in updates… and when that happens gui scripting goes haywire. One of the gotcha’s with both gui scripting and keystrokes is that sometimes the script goes too fast and these techniques can’t keep up with the speed of the program, so they often error. When this happens you need to slow down the script using small delays to allow the interface to keep up with the script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.