Requires Safari 5.1 or higher.
I wrote Quickscript solely for my own use, so I could have a way to run little scripts of my own devising that don’t deserve their own extension. Admittedly, it’s not very polished (not that any of my extensions are!) or even fully baked. It is, however, at least minimally functional.
(In case you’re wondering whether Quickscript supports scripts written for Greasemonkey, it doesn’t. Quickscript is a lot simpler and less ambitious than Greasemonkey, and it makes no effort to be compatible with that Firefox extension.)
How to use Quickscript
After installation, you’ll see a new button in your Safari toolbar. Clicking it will bring up the Quickscript menu, pictured below.
The menu will display, below the separator, any on-demand scripts you’ve saved. The commands above the separator open Quickscript’s Script Editor and Script Manager, respectively. (More on these below.)
Creating a script
To create a new script, choose Create/Edit Script… in the Quickscript menu. This will open the Script Editor, pictured below.
If you’ve already saved a script specifically for the site in the active tab, it will automatically appear in the Script Editor. If you’ve saved more than one such script, you’ll be able to choose another one by clicking the chevron at the right end of the Title box. If you haven’t yet saved any script for the current site, the Script Editor’s fields will be populated with placeholder values.
To create a Quickscript script, you need to supply four pieces of information:
- a title for the script,
- at least one URL pattern to determine which web pages the script will run on,
- whether the script should run on demand or automatically, and
- the script itself
For on-demand scripts, URL patterns determine whether a script will appear in the Quickscript menu when a given site or page is in the active browser tab. (If the page’s URL matches one of a script’s URL patterns, that script will appear in the menu while the page is in the active tab.) For autorun scripts, URL patterns determine whether a script will run automatically as soon as a page is loaded.
Quickscript supports the URL pattern format that is used internally by Safari extensions. The following documentation is copied verbatim from Apple’s Safari Extensions Development Guide:
A URL pattern takes the form Scheme://Domain/Path.
- Scheme can be
- Domain is the host domain, such as
- Path is the directory or webpage, such as
A URL pattern can include the
*character to match any string. This allows you to specify all pages in a particular domain, for example, without having to create an exhaustive list.
*character can be used anywhere in the domain or path, but not the scheme.
http://*/*— matches all http URLs
http://*.apple.com/*— matches all webpages from apple.com
http://developer.apple.com/*— matches all webpages from developer.apple.com
https://secure.example.com/accounts/*— matches all webpages from the accounts directory of secure.example.com that are delivered over HTTPS.
http://www.example.com/thepath/thepage.html— matches one webpage
There is a bug in Safari’s URL pattern parser such that a pattern that includes a
* character anywhere in a domain name except for the first part of the domain name results in the pattern matching every page everywhere. For example, due to this bug, the patterns
http://www.*.com/* are both equivalent to
http://*/*, but the pattern
http://*.example.com/* works correctly. To avoid this bug, please avoid constructing patterns that include a
* in any part of the domain name except the first part.
You can enter several patterns in the URL Patterns box. Each pattern must be on its own line.
You can use the buttons above the URL Patterns box to quickly enter http and https patterns based on the active tab’s URL. The Page button will enter patterns that match just the current page (and similar pages that share the same path but have different parameters in the query portion of the URL). Directory will match any URL that is the same as the current URL up to the last slash. Host will match any URL whose host (the part of the URL between the double slash and the first single slash) is the same as the current URL. Finally, Everywhere will match any http or https URL anywhere.
On-demand vs. autorun scripts
An on-demand script appears in the Quickscript menu whenever you are viewing a web page whose URL matches one of the script’s URL patterns. It does not run unless you select it in the menu. In contrast, an autorun script runs automatically as soon as you visit a page whose URL matches one of the script’s URL patterns. Autorun scripts do not appear in the Quickscript menu. You can change an on-demand script into an autorun script, or vice versa, by selecting the appropriate Type option and saving the script.
The script itself
If you enable the “Include jQuery” option, Quickscript will load jQuery into the web page before it loads your script. That means you’ll be able to use jQuery in your script. The version of jQuery that will be loaded is indicated by the version number on the checkbox label.
The Script Manager
To see all your saved scripts in one place, select Manage Scripts… in the Quickscript menu or click the Manage Scripts button in the Script Editor.
Here, you can create new scripts and edit or delete existing ones. To create a new script, click the + sign at the bottom of the left panel. To save a script after editing it, click the floppy disk icon at the top right corner of its editing area or type ⌘S while a text field is in focus. To delete a script, click either the trash can icon next to the script title on the left panel or the same icon at the top right corner of the script’s editing area.
Note: When you save an autorun script, any tabs that contain pages that match the script’s URL patterns will reload automatically.
If you use the Safari command “Remove All Website Data”, either from the Privacy tab of Safari preferences or from the Reset Safari dialog box, your Quickscript data—including all scripts and their associated URL patterns—will be deleted. If you want to retain your Quickscript data, before using the aforementioned command, make sure to back up the file
safari-extension_com.canisbos.quickscript-zanvztser6_0.localstorage located in the folder
~/Library/Safari/LocalStorage. After removing all website data, copy the file back to the folder and restart Safari.