Mac: reloading document in Chrome or Firefox?

后端 未结 4 1852
野趣味
野趣味 2020-12-28 22:52

How can I tell Chrome or Firefox to reload the document in the top window? Here\'s what I\'m using for Safari:

osascript -e \'
    tell application \"Safari         


        
相关标签:
4条回答
  • 2020-12-28 23:37

    Here's the code for Chrome:

    tell application "Google Chrome"
        tell the active tab of its first window
            reload
        end tell
    end tell
    

    Or more concisely:

    tell application "Google Chrome" to tell the active tab of its first window
        reload
    end tell
    
    0 讨论(0)
  • 2020-12-28 23:37

    Here's another way to do it in Safari without using JavaScript:

    tell application "Safari"
        tell its first document
            set its URL to (get its URL)
        end tell
    end tell
    
    0 讨论(0)
  • 2020-12-28 23:46

    Automator

    • Open Automator and choose a New Document
    • Choose Service

    A screengrab showing the document type dialog in Automator

    • Set Service receives to no input
    • Choose Run AppleScript action from the action list.
    • Paste the following code in the script:

     

    tell application "Google Chrome" to tell the active tab of its first window
    reload
    end tell
    

    A screengrab showing the automator window actions

    • Save the the service, for example, using the name Chrome Refresh

    System Preferences

    • Open System Preferences > Keyboard
    • In the Shortcuts tab, choose Services
    • Assign a new shortcut

    A screengrab showing System Preferences keyboard shortcut tab

    0 讨论(0)
  • 2020-12-28 23:48

    I do not think Firefox or Chrome have special Applescript support, but you can send the keystrokes (Cmd-R) to refresh the page:

    tell application "Firefox"
        activate
        tell application "System Events" to keystroke "r" using command down
    end tell
    
    0 讨论(0)
提交回复
热议问题