From Apple’s Launch Services Programming Guide (all emphasis mine):
All applications available on the user’s system must be registered to make them known to Launch Services and copy their document binding and other information into its database. It isn’t ordinarily necessary to perform this task explicitly, since a variety of utilities and services built into the Mac OS X system software take care of it automatically:
- A built-in background tool, run whenever the system is booted or a new user logs in, automatically searches the Applications folders in the system, network, local, and user domains and registers any new applications it finds there. (This operation is analogous to “rebuilding the desktop” in earlier versions of Mac OS.)
- The Finder automatically registers all applications as it becomes aware of them, such as when they are dragged onto the user’s disk or when the user navigates to a folder containing them.
- When the user attempts to open a document for which no preferred application can be found in the Launch Services database, the Finder presents a dialog asking the user to select an application with which to open the document. It then registers that application before launching it.
In spite of these automatic registration utilities, it may sometimes be necessary to register an application explicitly with Launch Services. For example, although developers are encouraged to package their applications so that they can be installed by simply dragging them onto the user’s disk, some applications may require more elaborate custom installer software. In such cases, the installer should call one of the Launch Services registration functions LSRegisterFSRef
or LSRegisterURL
to register the application explicitly.
Note the API calls needed by the only named manual registration procedure (source not available on opensource.apple.com, I’m afraid).
While working around a bug in processing of Launch Services on Leopard with FileVault enabled, I noticed that ~/Library/Preferences/com.apple.LaunchServices.plist
is:
processed only on login after boot, as input data to the buildup of the Launch Services database proper (FileVault-enabled Leopard often failed to do this step, resulting in seemingly lost user settings); and
cached as long as the machine is not rebooted.
Simply put, it’s the user domain persistence layer of Launch Services, and modifications to that persistence layer are only acknowledged on next processing – reboot or reseed.
I only got a partial solution, which works apart from a few small issues.
First of all, you can not store the URL in the filename (due to slashes and special characters) so you'd need to specify the Website name.
But more importantly, so far the CSV import is not implemented. Is CSV really a hard requirement, or could you get the list of URLs in a different format? If not, please update your question with exemplary lines of your CSV file. I'll work on it and update my answer as soon as possible.
on open_url(theUrl, theUrlName, x0, y0, xSize, ySize)
tell application "Safari"
open location theUrl
activate
set bounds of window 1 to {x0, y0, xSize, ySize}
set windowID to id of window 1
set the_state to missing value
repeat until the_state is "complete"
set the_state to (do JavaScript "document.readyState" in document 1)
delay 0.3
end repeat
set theFolder to POSIX path of (path to desktop as string)
set shellCommand to "/usr/sbin/screencapture -l " & windowID & " " & quoted form of (theFolder & "Screen Shot " & theUrlName & " " & xSize & "x" & ySize & ".png")
do shell script shellCommand
end tell
end open_url
set resolutionList to {{640, 480}, {1024, 768}}
set siteList to {{"http://www.apple.com", "Apple"}, {"http://www.google.com", "Google"}}
repeat with resolution in resolutionList
set xSize to item 1 of resolution
set ySize to item 2 of resolution
repeat with theSite in siteList
set theUrl to item 1 of theSite
set theUrlName to item 2 of theSite
open_url(theUrl, theUrlName, 0, 0, xSize, ySize)
end repeat
end repeat
Best Answer
To capture a window using
screencapture
in Terminal, you have two options:Interactively
You can use the
-o
option in conjunction with the-i
option to not capture the shadow of the window, e.g.:-oi
Programmatically
The
-i
option appears to be self-explanatory while the-l<windowid>
option gives no additional info as with the-i
option.The
<windowid>
, for some windows can be ascertained by using AppleScript in the following example:You can use the
-o
option in conjunction with the-l
option to not capture the shadow of the window, e.g.:-ol
Some applications will not work with this method, however here are some alternatives:
Reference: How do I find the windowid to pass to screencapture -l?
Note: I am not affiliated with these projects.