AppleScript to count pages of PDF documents via Skim

I found Skim to be the perfect replacement for Preview (ie, a fast app to review PDF documents with notes, etc.). And it also provides a decent AppleScript dictionary, so it’s also the perfect app to make one of those great time-savers. Follows sample code you can save as a droplet (and process a bunch of PDF files via drag & drop) or as a compiled script to be run from any script launcher:

open (get selection of application "Finder")

on open pdflst
	set cnt to 0
	repeat with i from 1 to count pdflst
		--> just in case comes from run handler...
		tell application "Finder" to set pdfFile to (pdflst's item i as alias)
		tell application "Skim"
			open pdfFile
			set cnt to cnt + (page count of (get info of document 1))
			close document 1 saving no
		end tell
	end repeat
	
	display dialog ("" & cnt & " pages for " & (count pdflst) & " documents...") with icon note
end open

I know it’s trivial code, but still you must spend some time to find a solution for your PDF-page-count needs, and this is a fast and free one.

Advertisement

Backup remote mysql databases to local MAMP via AppleScript/SSH

Requirements: access to the remote machine (usually a server) via SSH.

I backup my databases to the local installation of MAMP (stands for Mac-Apache-MySQL-PHP), but you can specify any directory you wish.

First step: do some stuff, so you can login automatically (no password prompt) to the remote machine. I followed the steps at http://ubuntuforums.org/showthread.php?t=30709 and it worked flawlessly. In the first step exposed there, just type what the folk says, then “enter” all the time long (no need to enter data).

After you successfully copy the public key to the remote server, just copy-paste the following to your script editor, modify what you need to match your settings and hit “Run”:

--> this is the folder where the remote "mysql" dir will be copied
--> I choose MAMP's one, but you can choose any for backup purposes
set localDir to "User:Library:Application Support:appsolute:MAMP PRO:db:"

--> enter your server, the dir where your "mysql" dir is located (usually something as /var/lib)
--> and move it to whatever location is available via HTTP
--> if you don't have such service, you can use "scp" to copy the file to your machine
--> but then you must setup your machine to accept SSH connections
with timeout of 3600 seconds --> 1 hour
do shell script "ssh -l root server.com 'cd /var/lib; tar -zcf mysql.tar.gz mysql;mv mysql.tar.gz /var/www'"
end timeout

--> download tgz file and remove pre-existing "mysql" folder in local machine (not sure yours, mine yes)
do shell script "cd " & quoted form of POSIX path of localDir & "; curl -O http://www.server.com/mysql.tar.gz; rm -rf mysql;"

--> unpack
tell application "Finder" to open (localDir & "mysql.tar.gz")

--> remove tgz file from remote and local servers (I'll keep the uncompressed dir)
do shell script "ssh -l root qilania.com 'rm /var/www/mysql.tar.gz'; rm " & quoted form of POSIX path of (localDir & "mysql.tar.gz")

Cheers!

EDIT: See this post for a different option (supports other db engines, such as InnoDB).

No scrolling maps in OpenSpace

Seems this is a FAQ for many OpenSpace users and it has been answered many times in their support forums. There isn’t support for no-scrollable maps in version 1.x of OpenSpace and it has been announced as a new feature for the incoming version 2.

In the mean time, while in the middle of the development of qilania, we found a workaround. Basically, you must attach the AvatarEvent “AVATAR_CREATED”, then call the method “centerViewOnTile”. You must make sure, though, that it exists a tile in the related position, so SmartFox/OpenSpace can find it using the z-index, which seems a requirement for “centerViewOnTile” to work. Sample code:

// os is the instance of the OpenSpace component in the stage
os.addEventListener(AvatarEvent.AVATAR_CREATED, onAvatarCreated)

function onAvatarCreated(evt:AvatarEvent):void {
	var pos:Object  = {px: 12, py: 12, pz:0};
	os.centerViewOnTile(pos);
}

You can know which tile you wish the viewport centered-in just making rollover in the map editor of the OpenSpace Editor. As stated, make sure there is a tile in such position of the tilegrid (being walkable or no walkable) by looking for the “z” property (close to x and y).

Appart from this, we created a background which must fit in the tilegrid (so, be smaller than the grid).

You must know as well that some actions of the avatar, such as teleportation, will fire “centerViewOnMyAvatar” (which will move the viewport), so immediately after the teleportation you must use again the “centerViewOnTile” method.

Most probably it would do the trick using a zoomed map (documentation says that using zoom will disable map auto-scrolling), but that would make the development process (basically illustration) a bit more complicated than it is already.

But there are more workarounds for sure, and you can find various in the support forums of OpenSpace.

FLA to PNG via AppleScript plus JSFL

We use this as a droplet, so we can convert dropped FLA files to PNG in a shot. The original script is much larger, as PNG files are post-processed before using them (need some tweaks in GraphicConverter or a similar apple-scriptable app), but it is a skeleton you can use in many little automation projects involving the wonderful world of AppleScript and Flash Javascript (aka JSFL), the language used to automate and extend the Flash IDE capabilities.

AppleScript --> FLA to PNG

AppleScript --> FLA to PNG (click to enlarge)

The FLA file will be exported as PNG using the last settings you used to export a PNG file.

You can download it here.

FileMaker to MySQL via AppleScript

This is the AppleScript code we use to pass data from FileMaker to a remote MySQL database. It requires FileMaker, the MySQL binary installed in your machine and a connection to a remote MySQL-powered server.

The “code” tag is crap, so I’ll post an image of the code and a link to the code itself. You can download it here.

AppleScript --> FileMaker to MySQL

AppleScript --> FileMaker to MySQL (click to enlarge)

This way we feel comfortable working “at home” with a full-blown interface in FileMaker and we can populate changes to the server when needed.