2010-01-19 34 views

Trả lời

9

Tôi không nghĩ rằng Firefox hoặc Chrome có hỗ trợ AppleScript đặc biệt, nhưng bạn có thể gửi các tổ hợp phím (Cmd-R) để làm mới trang:

tell application "Firefox" 
    activate 
    tell application "System Events" to keystroke "r" using command down 
end tell 
+0

Firefox được cho là đã bị hỏng với phiên bản 3.5.x hiện tại. –

+0

Tiện lợi!Điều này phù hợp với cả ba trình duyệt, sử dụng "Firefox", "Google Chrome" và "Safari" làm chuỗi ứng dụng. –

5

Dưới đây là một cách khác để làm điều đó trong Safari mà không sử dụng JavaScript:

tell application "Safari" 
    tell its first document 
     set its URL to (get its URL) 
    end tell 
end tell 
38

Dưới đây là đoạn code cho Chrome:

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

Hoặc ngắn gọn hơn:

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

Kịch bản này xứng đáng có nhiều upvotes IMO hơn vì nó không yêu cầu bạn đưa Trình duyệt vào trọng tâm trước khi tải lại - Đây là chìa khóa. – bitwit

+1

Bạn cũng có thể sử dụng "tab đầu tiên" thay vì "tab hoạt động". – blockloop

1

Automator

  • mở Automator và chọn một New Document
  • Chọn Dịch vụ

A screengrab showing the document type dialog in Automator

  • Set Dịch vụ nhận-không có đầu vào
  • Chọn Run AppleScript hành động từ danh sách hành động.
  • Dán đoạn mã sau trong kịch bản:

 

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 dịch vụ, ví dụ, sử dụng tên Chrome Refresh

System Preferences

  • mở System Preferences>Keyboard
  • Trong Shortcuts tab, chọn Dịch vụ
  • Gán một phím tắt mới

A screengrab showing System Preferences keyboard shortcut tab

Các vấn đề liên quan