The Verb Set
UserTalk includes a full complement of verbs to deal with your operating system. These verbs can be divided into the following categories:
We'll look briefly at each of these verb types in the following sections. Details on each verb can be found in DocServer.
File Verbs
There are 67 cross-platform file verbs. They enable you to:
These are just some of the dozens of functions you can perform on files, folders, and volumes with the file verbs.
Launch Verbs
With the launch verbs, you can launch applications and have applications open a document.
On the Macintosh, you can also launch any object that appears in the Apple menu, any Control Panel, any application, or any code resource (such as an FKEY).
System Verbs
System verbs deal for the most part with applications that are running. You can use Frontier verbs to:
Many of these features are also available in the verbs that are specific to an application, e.g. uBASE.bringToFront instead of the more generic sys.bringAppToFront.
Speaker Verbs
You can set up sound parameters and activate the system's speaker with the Frontier speaker verbs.
Finder Verbs
The Finder is an application that comes with your Macintosh. (You'd be surprised how many people don't know that!) Finder verbs can:
All of these features work in System 7 or greater, the "Scriptable Finder" is not required. Frontier supports many additional features if you have the Scriptable Finder (bundled with System 7.5, available for earlier releases). Verbs that work with the original System 7 Finder are in the "FinderClassic" table. The new Finder table contains the original verbs plus about 20 new ones.
Using system oriented verbs in a script
We have two examples, a Windows and a Macintosh example.
The Windows example adds Internet Shortcuts to your Microsoft Internet Explorer's Favorites list. The Macintosh example adds aliases of files to your Apple Menu Items folder.
One of the useful features of Microsoft Internet Explorer and the web/desktop integration is a menu in your Start Menu that lists your web Favorites. The list of Favorites in your Start Menu is the same list of Favorites in Internet Explorer.
This list of Favorites is stored in a folder on your hard drive. Each favorite is a separate file, an Internet Shortcut file.
The format for Internet Shortcut files is very simple and Frontier can make those files easily. With Frontier's file and string verbs you can create new favorites from within Frontier. The example here could be the basis for a favorites management system, written entirely with Frontier scripts.
Creating an Internet Shortcut file
You can create an Internet Shortcut and write it to disk with a one-line script:
file.writeWholeFile ("C:\\Scripting News.url",\ "[InternetShortcut]\r\nURL=http://www.scripting.com/\r\n")
The above script creates a file called "Scripting News.url" at the top level of your C drive. If you double-click on the file, Internet Explorer opens and loads the Scripting News page at http://www.scripting.com/.
But that script's not generally useful as-is. We want a script that creates a shortcut for any page with any URL.
Note the use of the file.writeWholeFile verb. This verb has two required parameters. The first parameter is the path on disk where the file should be stored. The second parameter is the content of the file. If you work often with files in Frontier, you'll use this verb frequently.
Any page name, any URL
We can make this script a little more useful by making it more general.
on newFavorite (pageName, url) local (f = "C:\\" + pageName + ".url") local (s = "[InternetShorcut]\r\nURL=" + url + "\r\n") file.writeWholeFile (f, s)
This script takes two parameters: the name of the page and the URL. It then creates the Internet Shortcut and stores it at the top level of your C drive. The name of the file is the same as the page name, but with a .url extension.
You can't run the above script as-is unless you add a line below it. For example:
on newFavorite (pageName, url) local (f = "C:\\" + pageName + ".url") local (s = "[InternetShorcut]\r\nURL=" + url + "\r\n") file.writeWholeFile (f, s) newFavorite ("Frontier 5", "http://www.scripting.com/frontier5/")
You could call this script from any other script to create a favorite file.
So now we can create a favorite file for any page with any name and any URL. But...
Where is the Favorites folder?
A little exploration tells us that the Favorites folder is one of two places.
On Windows 95 systems, the Favorites folder is on the same level as the System folder. In practice, that usually means it's at C:\Windows\Favorites\.
On Windows NT systems, the Favorites folder is at the same level as the current user's Start menu. This will usually be at a path like: C:\Winnt\Profiles\Administrator\Favorites\.
Here's a script that finds the Favorites folder, no matter which operating system you're using:
on getFavoritesFolder () local (favoritesFolder) if not defined (user.prefs.dialogs.favoritesFolder) user.prefs.dialogs.favoritesFolder = "" favoritesFolder = user.prefs.dialogs.favoritesFolder if not (file.exists (favoritesFolder)) case sys.os () "WinNT" favoritesFolder = file.getSpecialFolderPath ("", "StartMenu", false) "Win95" favoritesFolder = file.getSpecialFolderPath ("", "System", false) favoritesFolder = file.folderFromPath (favoritesFolder) favoritesFolder = favoritesFolder + "Favorites\\" if not (file.exists (favoritesFolder)) if not (file.getFolderDialog ("Where is your Favorites Folder?",\ @user.prefs.dialogs.favoritesFolder)) return (false) return (user.prefs.dialogs.favoritesFolder) dialog.notify (getFavoritesFolder ())
The first thing the script does is set up a cell in the Object Database to store the location of the Favorites folder. We've decided to store the location in the user.prefs.dialogs table, in the favoritesFolder cell.
The first time this script is called, that cell doesn't exist, so the script creates it empty.
The script then sets the local variable favoritesFolder equal to the contents of that cell. This script wouldn't have to use a local variable at all, but we do it in this case to save a little typing.
If the favoritesFolder variable doesn't contain a path to the Favorites folder, the script tries to calculate the location of the Favorites folder. It makes its best guess. If it's Windows NT the script looks one place, if Windows 95 another. That's what the case statement is for.
The file.getSpecialFolderPath verb gets the path to certain special folders. For instance, to find the path to the Start Menu, a script calls file.getSpecialFolderPath ("", "StartMenu", false). The first parameter, "", can be empty to specify the default, system volume. The second parameter is the name of the special folder. The third parameter specifies whether or not to create the folder if it doesn't exist. (You pretty much always make that third parameter false -- these special folders almost always exist, as they're maintained by the operating system.)
The file.folderFromPath verb pops off one level of a path.
Then the script adds the name of the Favorites folder (which is "Favorites", usually) to the path.
The script checks again to see if its calculated path points to a real folder. It might not have found the Favorites folder -- this might be a non-English system, or the user may have moved their Favorites folder to a non-standard location. If the script hasn't found the Favorites folder, the script asks the user to show where the Favorites folder is, via the Frontier verb file.getFolderDialog.
The file.getFolderDialog verb presents s dialog box that's a standard tree view of the folder hierarchy. The user selects a folder and clicks OK. The script then stores the location of the Favorites folder -- so that next time it won't have to ask the user where his or her Favorites folder is, it will remember.
The last thing the script does is return the path to the Favorites folder.
The line that starts with dialog.notify at the end of the script is for debugging, so you can run the script by clicking the Run button and get immediate feedback that it worked correctly.
The finished script
To remember what the original goal was: we wanted a script that, given two parameters -- a page name and a URL -- creates a new entry in the Favorites Menu.
There are numerous different ways to assemble the above elements into a finished script. One sensible way would have to been to create several separate scripts in your Workspace table: a getFavoritesFolder script, a writeShortcut script, and a newFavorite script which called the first two. Such "factoring promotes the re-use of scripts, and is considered a very good thing. Re-use is part of the Frontier philosophy.
But for the sake of example, let's put all the code together into one big script. You could put the script in your Workspace table, at workspace.newFavorite. Here's the listing for the final version of the script:
on newFavorite (pageName="", URL="") local (f) on getFavoritesFolder () //return the path to the Favorites folder local (favoritesFolder) if not defined (user.prefs.dialogs.favoritesFolder) user.prefs.dialogs.favoritesFolder = "" favoritesFolder = user.prefs.dialogs.favoritesFolder if not (file.exists (favoritesFolder)) case sys.os () "WinNT" favoritesFolder = file.getSpecialFolderPath ("", "StartMenu", false) "Win95" favoritesFolder = file.getSpecialFolderPath ("", "System", false) favoritesFolder = file.folderFromPath (favoritesFolder) favoritesFolder = favoritesFolder + "Favorites\\" if not (file.exists (favoritesFolder)) if not (file.getFolderDialog ("Where is your Favorites Folder?",\ @user.prefs.dialogs.favoritesFolder)) return (false) return (user.prefs.dialogs.favoritesFolder) on writeShortcut (path, loc) //write an Internet Shortcut to disk local (s) s = "[InternetShortcut]\r\nURL=" + loc + "\r\n" file.writeWholeFile (path, s)} if pageName == "" if not (dialog.ask ("Name of Page?", @pageName)) return (false) if URL == "" if not (pageName contains " ") URL = "http://www." + pageName + ".com/"} if not (dialog.ask ("URL:", @URL)) return (false) f = getFavoritesFolder () + pageName + ".url" writeShortcut (f, URL) return (true) newFavorite ()
This is a pretty useful script. Whenever you want to add an item to your Favorites menu from within Frontier, your script can call this script. Or you could attach this script to a menu item.
Here's a simple example of you might add several Favorites to a Favorites menu.
workspace.newFavorite ("Scripting News", "http://www.scripting.com/") workspace.newFavorite ("Frontier 5", "http://www.scripting.com/frontier5/") workspace.newFavorite (Fat Pages, "http://www.scripting.com/fatpages/") workspace.newFavorite ("Baseball News", "http://www.cnnsi.com/baseball/")
One of the handiest things in Macintosh System 7 is the idea of an alias file. An alias file is a small file whose sole purpose is to point to another file. Any kind of Macintosh file -- application, document, even Control Panel -- can have one or more alias files. You can put an alias anywhere on the system and it will be able to find the original file.
Many people keep aliases of frequently used files in the Apple Menu Items folder in the System Folder so that they appear as items in the Apple menu. Carrying out this process has a surprising number of steps:
The Frontier verb file.newAlias carries out these same tasks with one command. You simply tell the verb what file you wish to create an alias for and the name of the alias file, including the path name to the Apple Menu Items folder, and it takes care of the rest. Here's a typical use of this verb:
file.newAlias ("Disk:Apps:Hot App",\ "Disk:System Folder:Apple Menu Items:Hot App")
Pretty simple, right?
The problem, of course, is that this one-line script isn't very useful if you want to move another new alias file to the Apple menu. You'd have to re-type the full path and file names (or at least substantial parts of them) each time you wanted to do this task. Let's create a slightly more flexible version of this script.
Our script will ask the user to select a file. It will then ask for the name the alias should have in the Apple menu. Finally, it will create and copy the alias using the file.newAlias verb.
First, we need a line that will allow the user to select the file to alias. Check out the DocServer page for file verbs. Looking through the list, you should see a verb called file.getFileDialog. It sounds like the right one. It takes three arguments: a prompt with which to guide the user, the address of the Object Database cell or local variable in which the user's answer is to be stored, and the type of file to be shown (using zero to indicate that any type is acceptable).
Here is a line of Frontier code which will enable the user to pick a file of any type and put its full path name into a variable called f1 (which should first be declared as a local):
file.getFileDialog ("File to create alias for?", @f1, 0)
Next, we need a line that asks the user for the name of the file to create in the Apple Menu Items folder. We can use dialog.ask for this purpose (after creating a local variable "f2" to hold the new name):
dialog.ask("Save in Apple Menu under what name?", @f2)
Other than an escape valve for the user to cancel this operation, we are now ready to enter the code. Here is the full listing of the storeNewAlias script:
In good Frontier style, we use the "on" keyword to define the script header. (To run or debug the script from the same window, add a "storeNewAlias ()" line at the end of the script as a "summit.") We declare two local variables, initializing them both in this case to empty strings. Next, we prompt the user for the file. Clicking the "Cancel" button in this dialog returns false, resulting in the script being exited and returning false to the calling script.
The verb file.fileFromPath extracts only the file name from the full path of the file chosen by the user; the result is used as the default response to the next dialog. Again, if the user clicks "Cancel," the script terminates and returns false to the calling script.
Finally, we use file.newAlias to create the alias of the file whose full path name is stored in f1 and store it in the right place on the system drive. Notice the use of the Frontier verb file.getSystemFolderPath, which returns the path to the System Folder on the startup volume. This makes the script generic to all users' systems (including internationally).
When we're done, we beep the speaker and let the user know we've finished. Then we return true so the calling script will know all went well.
If creating aliases for the Apple Menu is something you do a lot, you might want to connect this new script to a menu command.
This site scripted by Frontier.