More Advanced AppleScript Code

Shipping Carton for Apple II
Shipping Carton for Apple II

This is a continuation of Advanced Applescript Code. This does not follow a particular order of difficulty that supercedes the previous site; it is, in fact, just more scripts on a variety of subjects. If you are a total newbie to AppleScript, though, please see my original website Free AppleScript Code for Beginners first to get started and then come back here to build on your knowledge. In either case, come here to see new content as it becomes available.

Company Field and Resulting List Dialog
Company Field and Resulting List Dialog

Find Record in FileMaker Database

Use this script to search for a record in a FileMaker database from another FileMaker database. Just substitute the name of your target database for 'YourDatabaseName' below. Note that this starts out from one database with a field containing a list of company names. The 'listSort (theList)' function sorts the company names alphabetically before displaying the 'choose from list' dialog. After the user chooses an item and clicks the 'Go' button, FileMaker goes to the other database and finds the record matching the chosen company name.

Now, here is the Script:

try
set restoreDelimiters to text item delimiters of AppleScript
set text item delimiters of AppleScript to return
set theUnsorted to text items of (get data cell "Company" of current record)
set listCount to (count text items in theUnsorted)
set cleanUnsorted to {}
set repeatCount to 1
repeat listCount times
if not ((text item repeatCount of theUnsorted) is in cleanUnsorted) then set end of cleanUnsorted to (text item repeatCount of theUnsorted)
set repeatCount to (repeatCount + 1)
end repeat
set theSorted to (my listSort (cleanUnsorted)) as list
set targetRecord to (choose from list theSorted with prompt "Find Record:" with title "Company" default items (text item 1 of theSorted) OK button name "Go")
if targetRecord = false then error
go to database "YourDatabase.fp7"
show every record of current table
show every record where its cell "Name" contains targetRecord
set text item delimiters of AppleScript to restoreDelimiters
show every record of current table
on error
return
end try

on listSort (theList)
	set indexList to {}
	set sortedList to {}
	repeat (number of items in theList) times
		set lowItem to ""
		repeat with i from 1 to (number of items in theList)
			if i is not in indexList then
				set thisItem to item i of theList as text
				if lowItem is "" then
					set lowItem to thisItem
					set lowItemIndex to i
				else if thisItem comes before lowItem then
					set lowItem to thisItem
					set lowItemIndex to i
				end if
			end if
		end repeat
		set end of sortedList to lowItem
		set end of indexList to lowItemIndex
	end repeat
	return sortedList
end listSort

For a more basic 'choose from list' dialog, click here

Backup a Folder's Contents in Finder

This script, directed to the Finder, takes a folder that you choose as a source folder and gives you the option of saving the files contained in that folder to an existing folder or to a new folder that you specify.

Take note below that in the 'choose folder' dialog there is a button at the lower left that you can click to specify a new folder as your destination folder. Since none of the code is 'hard wired' you should be able to use it 'as is' without any modification.

Note also that I have trapped for error -15267, which is triggered when you attempt to copy over a file which already exists in the destination folder. However, if you are sure that you want to write over over duplicates, you can add 'with replacing' to the end of line 20 and no error will be triggered and duplicates will be replaced by the items you are moving automatically. This should be done with caution, though, as there is no way to 'undo' this action.

The code:

tell application "Finder"
	try
		set saveDelimiters to text item delimiters of AppleScript
		--Remember that processing with the finder requires colon delimited file names:
		set folderToCopy to (choose folder with prompt "Choose a folder to copy:") as alias
		set text item delimiters of AppleScript to ":"
		set sourceFolderName to (text item -2 of (folderToCopy as string))
		set destinationFolder to (choose folder with prompt "Choose a destination folder for items in folder '" & sourceFolderName & "' or choose 'New Folder' at bottom left to create a new folder:") as alias
		set newFolder to destinationFolder
		set destinationFolderName to (text item -2 of (destinationFolder as string))
		set text item delimiters of AppleScript to saveDelimiters
		if not (folder newFolder exists) then set destinationFolder to (make new folder with properties {name:newFolder, location:destinationFolder})
		--This is critical for the file transfer processing:
		set bkpFiles to a reference to entire contents of folder folderToCopy
		set backupConfirm to button returned of (display alert "Copy files" message "Copy files from folder '" & sourceFolderName & "' to folder '" & destinationFolderName & "' with extension '.bkp'?" as informational buttons {"Abort", "OK"} default button 2 giving up after 60)
		if backupConfirm = "Abort" then error
		repeat with theFile in bkpFiles
			set fileName to name of theFile as text
			select file fileName of folder sourceFolderName
			duplicate selection to folder newFolder  --optional with replacing
			set name of document file fileName of folder newFolder to (fileName & ".bkp")
		end repeat
		display alert "Backup Complete" message "Files from folder '" & sourceFolderName & "' have been saved to folder '" & destinationFolderName & "'." buttons "Done" default button 1 as informational giving up after 15
	on error theError number theNumber
		if theNumber = -15267 then
			display alert "Error Number " & theNumber message "The file '" & fileName & "' already exists in this location." as warning buttons {"OK"} default button 1
		else
			display alert "Error Number " & theNumber message theError
		end if
		tell application "AppleScript Editor" to activate --This line is optional, I put it here for my own testing purposes
	end try
end tell

Drag and Drop to get Properties of an Image

This is a convenient script for when you need to know some detail on an image or document. It takes the data derived from the Finder's 'info for' command and puts it in a form that can be displayed in a dialog.


With a little work, you could have it sent to a text document in AppleWorks or Word. To use this, paste the code into a new AppleScript window, go to File> Save and choose the 'Save as Application' option from the drop-down menu. Be sure that GUI Scripting is enabled. That's it !

property baseFileSize : 1024 --some would use 1000, 1024 bytes is equal to 1K

on open (targetImage)
	set saveDelimiters to text item delimiters of AppleScript
	tell application "Finder"
		activate
		set imageInfo to (info for targetImage)
		set defaultName to name of imageInfo
		set nameExt to name extension of imageInfo
		set imageSize to size of (info for targetImage)
		set imageSize to my convertSize(imageSize)
		set createDate to date string of (creation date of imageInfo)
		set modDate to date string of (modification date of imageInfo)
		set defaultApp to (default application of imageInfo) as string
		set imageInfoSheet to "Info for Image:" & return & return & "Name: " & defaultName & return & "Name Extension: " & nameExt & return & "Size: " & imageSize & return & "Creation Date: " & createDate & return & "Modification Date: " & modDate & return & "Default Application: " & defaultApp
		display alert defaultName message imageInfoSheet as informational
	end tell
	set text item delimiters of AppleScript to saveDelimiters
end open

on convertSize(imageSize)
	if imageSize > (baseFileSize ^ 4) then
		set {div_1, theUnit} to {(baseFileSize ^ 4), "TB"}
	else if imageSize is greater than or equal to (baseFileSize ^ 3) then
		set {div_1, theUnit} to {(baseFileSize ^ 3), "GB"}
	else if imageSize is greater than or equal to (baseFileSize ^ 2) then
		set {div_1, theUnit} to {(baseFileSize ^ 2), "MB"}
	else if imageSize is greater than or equal to baseFileSize then
		set {div_1, theUnit} to {baseFileSize, "KB"}
	else
		set {div_1, theUnit} to {1, "B"}
	end if
	set imageSize to (((imageSize div div_1) & "." & ((imageSize mod div_1) div (div_1 / 10)) as string) as real) as string
	if imageSize ends with ".0" then set imageSize to (text 1 thru -3 of imageSize)
	return (imageSize & " " & theUnit as string)
end convertSize

Special thanks to Nigel Garvey at MacScripter for convertSize function above.

Pages
Pages | Source

Convert AppleWorks Documents to Pages

A lot of people, including myself, are starting to use Pages or Word more, as AppleWorks has not been updated in ages. This script searches a folder for AppleWorks documents and when found, saves the original to a backup folder and copies their contents to a new Pages window, saves them and closes the document window.


It illustrates a method for converting a file to another format. It works really well with text files. It can also be put to use with other types of files as long as you keep in mind, that they must be of a similar type.

set itemPath to (choose folder with prompt "Choose a folder to scan for AppleWorks documents to convert to Pages:" without invisibles) as string
open itemPath
set itemCount to (count items in Finder window 1)
set desktopPath to path to desktop folder
if not (folder "AppleWorks Original Documents" exists) then set originalsFolder to (make new folder at desktopPath with properties {name:"AppleWorks Original Documents"})
try
set y to 0
repeat with x from 1 to itemCount
set theItem to (item x of Finder window 1) as alias
set fileInfo to (get info for theItem)
set fileKind to name extension of fileInfo
if fileKind = "cwk" then
tell application "Finder"
select theItem
duplicate selection to folder "AppleWorks Original Documents" with replacing
tell application "Pages"
activate
open theItem
close front window saving in my pagesSuffix(theItem)
end tell
end tell
set y to y + 1
end if
set x to x + 1
if x > itemCount then
set y to y as string
tell application "Finder" to activate
display alert y & " items" message "AppleWorks conversion to Pages is complete" as informational buttons {"Done"} default button 1 giving up after 24
exit repeat
end if
end repeat
on error errorMsg
display dialog errorMsg
end try

on pagesSuffix(theItem)
set targetItem to (get info for theItem)
set fileName to name of targetItem
set fileExtension to name extension of targetItem
if fileExtension is "" then
set shortName to fileName
else
set shortName to text 1 thru -((length of fileExtension) + 2) of fileName
end if
set convertName to (shortName & ".pages") as string
return convertName as string
end pagesSuffix

Note: the info for command, used above, is deprecated; although it still works, the script lines below are the preferred way to get the property info for a document.

tell application "System Events"
set fileInfo to (get the properties of theItem)
set fileKind to name extension of fileInfo
end tell

Create, Edit and Save a PowerPoint Presentation

Creates a PowerPoint presentation and sets fonts, colors and sizes for its slides and then saves the file to a specified place on your hard drive. As is the case with other Microsoft Applications, Powerpoint has some peculiarities in its syntax that you need to master if you want to become confident in scripting with it.

tell application "Microsoft PowerPoint"
activate
try
set deskPath to (path to desktop) & "Great Presentation" as string
set presentationReference to make new presentation
tell presentationReference
set newSlide to (make new slide at end with properties {layout:slide layout text slide})
tell newSlide
set content of text range of text frame of shape 1 to (text returned of (display dialog "Enter main header text:" default answer "Main Topic Header"))
tell font of text range of text frame of shape 1
set font name to (choose from list {"Arial", "Courier New", "Futura", "Lucida Grande", "Trebuchet"})
set font size to (choose from list {9, 10, 12, 24, 36, 48})
set font color to (choose color default color {31270, 38327, 65535})
end tell
set content of text range of text frame of shape 2 to (text returned of (display dialog "Enter subtopic text:" default answer "Sub-Topic Header"))
tell font of text range of text frame of shape 2
set font name to (choose from list {"Arial", "Courier New", "Futura", "Lucida Grande", "Trebuchet"})
set font size to (choose from list {9, 10, 12, 24, 36, 48})
set font color to (choose color default color {31270, 38327, 65535})
end tell
end tell
end tell
save presentationReference in deskPath as save as presentation
on error errorMsg
display dialog errorMsg
end try
end tell

One of the peculiarities of AppleScripting with PowerPoint is the persistent requirement of an object reference. The use of object references with AppleScript is not all that uncommon, but with Microsoft apps it goes to the extreme. Let's examine a few of these found here:

set presentationReference to make new presentation

set newSlide to (make new slide at end with properties {layout:slide layout text slide})

Unlike most applications, you can't just use an expression such as tell document 1 or presentation 1 or slide 1. You do have some limited use of the expression active presentation, but it is hard to predict when it can and cannot be used. So this is something to be ready for when scripting PowerPoint.

Two other curious aspects of PowerPoint scripting are the wordiness of some expressions:

content of text range of text frame of shape 1

font of text range of text frame of shape 2

and the unnatural, un-english-like flow of some others, such as:

save presentationReference in deskPath as save as presentation

If you bear these unusual aspects of PowerPoint in mind, and just switch gears a bit, you'll have a head start on understanding the syntax of AppleScript in these special cases with Microsoft applications .

Internet Security and Malware

Keeping Your Computer Safe from Viruses, Worms and Trojan Horses

If you've used the internet long enough, you know how important security issues are in protecting your personal info. Whether it be a worm or virus that corrupts your system or a Trojan horse that steals your personal info, there is always someone coming up with new malware to attack your system or personal info. Of course, you can buy virus protection software, which is good, but the best security measure against malware is just a simple tactic that costs you nothing: common sense. If you don't want your info to be stolen, then don't keep it on your computer (as discussed elsewhere) or save it on an old computer that is not connected to the internet. With that said, did you know that there is a simple way to protect your personal info from malware? It's called a screen shot.

For a related topic, go to: How to remove the Flashback malware from OS X Although these are not guaranteed methods for protecting yourself from a virus or malware, it is your best first defense and, once again it is free and common sense.

Open and Write to a TextEdit Document

Tracking User Actions

Use this script to track login dates of users. I use this as part of a FileMaker startup script for a database program where I store sensitive information that I want to be sure is not compromised by employees. It writes the name of the current user and the date and time that they logged in to a TextEdit doc. You could also extend this to track when the user logs out.

tell application "System Events"
set currentUser to (name of current user)
end tell

try
set theFile to (((path to desktop) as text) & "Login Folder:" & "Logins.txt") as alias
set accessFile to open for access theFile with write permission
get eof accessFile
if result > 0 then
set savedText to read accessFile
set eof accessFile to 0
set loginDate to ((current date) as string)
set loginText to "User: " & currentUser & " logged in on: " & loginDate & return & savedText
write loginText to accessFile
end if
close access accessFile
display alert "The text:" message "\"" & loginText & "\"" & return & return & "Has been copied to: " & theFile as informational giving up after 6
on error theError
display dialog theError
end try
Enter a Month, Day and Year and Get the Weekday

set restoreDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set defaultSearch to text items 2 thru 3 of (date string of (current date) as string) as string
set searchDate to text returned of (display dialog "Enter a date in the form: \"July 24, 2012\" to find day of week" with title "Get Weekday" default answer defaultSearch buttons "OK" default button "OK")
set resolveWeekday to (weekday of date searchDate) as string
display alert resolveWeekday message "The weekday for the date \"" & searchDate & "\"" buttons "OK" default button "OK"
set AppleScript's text item delimiters to restoreDelimiters
iTunes
iTunes | Source

Play iTunes Tracks by Filter

A Primer on iTunes AppleScript

A useful script for finding iTunes tracks based on criteria that you specify. You can search either by Album, by Artist or by a specified keyword. The data for each track is displayed in a dialog and then the track is played.

There's a lot you can do with this to make it more sophisticated. Whether or not you expand on the script, it still serves as a good overview of Applescripting with iTunes:. A few key points follow the script.

tell application "iTunes"
activate
try
set criteriaChoices to {"Album", "Artist", "Keyword"}
set searchCriteria to (choose from list criteriaChoices with title "Playback Choices"with prompt "Choose a search criteria:")
display dialog "Enter a search term for criteria '" & searchCriteria & "':" default answer "" with icon 1 buttons "Search" default button "Search"
set searchTerm to text returned of the result
if searchCriteria contains "Album" then
set trackCount to count (file tracks whose album contains searchTerm)
if trackCount > 0 then
repeat with trackMatch in (file tracks whose album contains searchTerm)
display alert (name of trackMatch as string) message "Time: " & (time of trackMatch as string) & return & "By " & (artist of trackMatch as string) & return & "From the album: " & (album of trackMatch as string) buttons "Play" default button "Play" as informational
play trackMatch
end repeat
else
error "not found"
end if
else if searchCriteria contains "Artist" then
set trackCount to count (file tracks whose artist contains searchTerm)
if trackCount &lt 0 then
repeat with trackMatch in (file tracks whose artist contains searchTerm)
display alert (name of trackMatch as string) message "Time: " & (time of trackMatch as string) & return & "By " & (artist of trackMatch as string) & return & "From the album: " & (album of trackMatch as string) buttons "Play" default button "Play" as informational
play trackMatch
end repeat
else
error "not found"
end if
else if searchCriteria contains "Keyword" then
if trackCount > 0 then
repeat with trackMatch in (file tracks whose name contains searchTerm)
display alert (name of trackMatch as string) message "Time: " & (time of trackMatch as string) & return & "By " & (artist of trackMatch as string) & return & "From the album: " & (album of trackMatch as string) buttons "Play" default button "Play" as informational
play trackMatch
end repeat
else
error "not found"
end if
end if
on error errorMsg
if errorMsg = "not found" then display alert "Search: " & searchTerm message "No tracks found for the given criteria and search term." buttons "OK" default button "OK" as warning
end try
end tell

Two points I want to draw attention to here. First, in the following lines:

if searchCriteria contains "Album" then
else if searchCriteria contains "Artist" then
else if searchCriteria contains "Keyword" then

We use 'contains' as opposed to 'is equal to' or '='. Why ? Because if we don't, AppleScript takes it literally, that is to say, including the quotes which would rule out all of the conditionals.

And second, the line:

error "not found"

which is at the end of each conditional block. This sends the script to the error handler of the try block and to a specific statement. You can have any number of these custom error handlers, merely by saying error and some quoted phrase that is directed to a specific part of the error handler.

Using Aliases and POSIX Paths

Over the time that I have been writing AppleScripts, I have found that one of the most difficult, if not frustrating, tasks of writing scripts is referencing files by path so that they can be accessed by other applications.

As you'll see below, creating a reference that is understandable by the Finder is fairly simple (not always though). These are common alias references, most of which are understood by pre-OSX versions of the system as well as OSX. In the following section we will not only take a look at how to get 'regular' file paths, but also how to get POSIX paths (like UNIX) that are sometimes useful in deriving a path in a format that you may need. First, a number of examples of regular, alias paths:

tell application "Finder" to get folder "FileMaker Databases" of desktop


--> result: folder "FileMaker Databases" of folder "Desktop" of folder "administrator" of folder "Users" of startup disk of application "Finder"

tell application "Finder"
set targetFolder to (get folder "FileMaker Databases" of desktop as alias)
open targetFolder
end tell


--> result: alias "Macintosh HD:Users:administrator:Desktop:FileMaker Databases:"

set monthReportDoc to "Monthly Reports " & "2008.fp5"
tell application "Finder" to set targetDoc to (get file monthReportDoc of folder "FileMaker Databases" of desktop as alias)


--> result: alias "Macintosh HD:Users:administrator:Desktop:FileMaker Databases:Monthly Reports 2008.fp5"

This script gets the path to a folder on the desktop containing FileMaker Pro databases and concatenates it together with a file name and sends it to FileMaker Pro to open it:

set monthReportDoc to "Monthly Reports " & "2008.fp5"
tell application "Finder" to set targetDoc to (get file monthReportDoc of folder "FileMaker Databases" of desktop)


--> result: document file "Monthly Reports 2008.fp5" of folder "FileMaker Databases" of folder "Desktop" of folder "administrator" of folder "Users" of startup disk of application "Finder"

tell application "FileMaker Pro"
activate
open targetDoc
end tell

Sometimes you must specify the POSIX path. The only real difference is that the regular Mac OS path and the POSIX version differ in that the POSIX (UNIX) path separates the hierarchy (deliminates) with the forward slash '/', omitting the actual name of the HD, while the regular Mac path is delimited by ':' and includes the name of the hard Disk. Examine these two statements:

POSIX: "/Users/administrator/Desktop/FileMaker Databases/"


Mac Path: "Macintosh HD:Users:administrator:Desktop: FileMaker Databases:"

Follow this to go from an Alias to a POSIX path:

First, the path to the folder "FileMaker Databases" :

tell application "Finder" to get folder "FileMaker Databases" of desktop



--> result: folder "FileMaker Databases" of folder "Desktop" of folder "administrator" of folder "Users" of startup disk of application "Finder"

Then, the alias path to the folder:

tell application "Finder" to get folder "FileMaker Databases" of desktop as alias



--> result: alias "Macintosh HD:Users:administrator:Desktop:FileMaker Databases:"

tell application "Finder" to get the POSIX path of (folder "FileMaker Databases" of desktop as alias)



(folder "FileMaker Databases" of desktop as alias) This, since it is enclosed in parenthesis, will be evaluated first. Then the POSIX path of that is derived.
--> result: "/Users/administrator/Desktop/FileMaker Databases/"

Then going from a POSIX to an Alias. Using the previous example:

"/Users/administrator/Desktop/FileMaker Databases/" as POSIX file
--> result: file "Macintosh HD:Users:administrator:Desktop:FileMaker Databases:"

Since this is executed from left to right:


"/Users/administrator/Desktop/FileMaker Databases/" as POSIX file as alias



--> result: alias "Macintosh HD:Users:administrator:Desktop:FileMaker Databases:"

Finally, if you're not exhausted by now, look at these comparisons, which give the same result:

folder "Macintosh HD:Users:administrator:Desktop:FileMaker Databases:"



item "Macintosh HD:Users:administrator:Desktop:FileMaker Databases:"

As do these:

folder "FileMaker Databases" of folder "Desktop" of folder "administrator" of folder "Users" of startup disk of application "Finder"



item "FileMaker Databases" of folder "Desktop" of folder "administrator" of folder "Users" of startup disk of application "Finder"

A little precursor for what is to come:

tell application "Finder" to get the URL of home
--"file://localhost/Users/administrator/"
AppleWorks 6
AppleWorks 6 | Source

Script to Set AppleWorks Font from 'Choose from List'

I came upon this one sort of by chance as I was working on another script (that I finally resolved!). This uses GUI to get the first 10 fonts of the font menu in AppleWorks, displays them in a 'choose from list' dialog and, when you make a selection, selects the entire contents of the frontmost document and sets the font to the result.
I originally wrote this to include every font in the menu, but when I ran it, it took quite a while to compile the names of all of the fonts I had on my system (I have a lot of fonts, and I think I have a fairly standard system). By the way, don't be intimidated by the nested tell blocks, this script is straightforward regardless.

Just a reminder, once again, be sure that Assistive Devices is enabled or this will not run:

try
	tell application "AppleWorks 6" to activate
	tell application "System Events"
	--This gets the names of the first 10 of all of the available fonts
		tell process "AppleWorks 6"
			tell menu bar 1
				tell menu bar item "Text"
					tell menu "Text"
						tell menu item "Font"
							tell menu "Font"
								set theFonts to ""
								repeat with x from 1 to 10
									set theFonts to (theFonts & name of menu item x) as list
								end repeat
							end tell
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
	
	tell application "AppleWorks 6"
		activate
		tell document 1
			select every text
			set theFont to (choose from list theFonts)
			set the font of the selection to theFont
		end tell
	end tell
on error theError
	display dialog theError
end try

Security Issues with GUI and the Internet

GUI Scripting is a great way to script those applications that do not have a scripting vocabulary and for those with limited scripting support. You may, however, have thought to yourself: "Is it really a good idea to leave it enabled all of the time, especially when I work on the internet a lot?" There are differing opinions on that, but I would say unequivocally - No!

The reason is this: Many of your system preferences and other critical files on your computer cannot be easily scripted without GUI (if at all). Even if you don't spend much time on the internet, if you share your computer with other users that you aren't sure you can totally trust, you should at least set a password to authenticate its use.

To play it safe, I begin every GUI script with:

enabledGUIScripting(true)

And end every GUI script with:

enabledGUIScripting(false)

on enabledGUIScripting(theBoolean)
	tell application "System Events"
		activate
		set UI elements enabled to theBoolean
		return UI elements enabled
	end tell
end enabledGUIScripting

Following this practice, I ensure that no-one has access to GUI during idle or if I forget to manually disable GUI when I leave my computer while connected to the internet.

NOTE OF CAUTION: Quitting your browser does not protect you from potential hackers. Even if you have a system-wide password set, which I highly advise, you are still not completely protected.

To enable/disable GUI Scripting go to System Preferences from the Apple menu and click on Universal Access at the bottom of the window and click on 'Enable access for assistive devices'. Optionally you can go to YourHD>Applications>AppleScript>AppleScript Utility to set it there.

Facebook
Facebook | Source

Revealing Personal Info on FaceBook and Twitter

This post is a sort of continuation of a previous post on security and GUI. This does not contain any script samples, but is rather information of general utility to all who use the internet and are concerned about potential security issues.

I was inspired to write this post, in part, after reading an article in a local newspaper on mistakes that people make when using Twitter. The most striking of which was a particular case in which someone revealed that they were about to go on vacation.

On the surface, this seems pretty harmless, but consider the fact that this person also provided their real name in their profile and furthermore (real big mistake), the dates that they would be away.

I know that most people would not be foolish enough to give out sensitive info over the internet, so you're probably thinking: "So what if I reveal my real name in my profile?"

It is not widely known, but internet scammers routinely follow Twitter (and FaceBook) looking for potential victims for identity theft. If you have revealed your real name in your profile, they will 'follow' your Tweets to see what other personal information you will reveal, because they know that the typical 'tweeter' feels at ease with saying anything that they want to say, thinking that tweets are secure.

If you look like a good candidate for identity theft they will compile their own profile of you and wreak havoc on your credit. It is also not widely known that thieves can sometimes find out where you live and literally 'rob you' in the given scenario above. Revealing your name alone can make it possible for scammers to potentially find out your social security number and more, and then, well, be forewarned and protect yourself.

Passwords and Email Etc

What was said in the previous section about your profile applies to email as well; you just have to make a judgement call as to your risk based on how much you work on the internet and the kind of info you share. I spend a lot of time on the internet doing a variety of things, so the measures that I must take may be more stringent than yours. Once again, you have to judge that for yourself.

One issue that applies to email is managing your inbox. If you're like me, you scrutinize everything that comes in and delete anything that looks questionable. Some say that you should delete and, by all means, do not open anything that does not come from someone you know or a site that you know. I wouldn't suggest this extreme for everyone and have to admit that with all I do over the internet, I don't even entirely adhere to that proviso. I do have a few caveats to suggest though.

The first one is, do not fall prey to scams claiming that you have inherited funds from a distant relative (usually from some foreign country). The most current of which supposedly originates through The Bank of Nigeria (see link below for other scams). These people will try to play off of your emotions, trying to see if they can get an initial 'hook' to lure you in. Once they have you, they will try to convince you again and again that some fee is required in order to release your supposed inheritance. The old rule of thumb applies here: 'If it looks to good to be true, it probably is!'

For some other scams go to: www.scam.com/

The second one relates to file suffixes. Do not open any emails containing attachments with prefixes that you do not recognize. By far the most common is '.exe'; it stands for execute. It can be a good thing, such as software that you wanted to download, but it also could by spyware to get hold of your personal information or even a virus to corrupt your system. In fact, some of these files are so malicious, that they wiill both steal your info as well as corrupt your computer.

Note: If you use a Mac, don't even concern yourself with 'exe' files in the first place, because they are useless files that your computer may open up, but it will come up as complete gibberish and can't harm your computer anyway.

On the subject of passwords with email etc, be creative (and clever) about your choices. In general, try to be a little cryptic. For example, instead of using a password such as say, bumblebee, use bum56blebee or bum#bleb$ee. Interspersing symbols or numbers in your password makes your password very difficult to figure out and, as long as you don't make it too complicated, you should still be able to easily remember it.


The reason for such measures is this: there are people out there who will find out your email address and then run a robot algorithm program that will try different combinations of common English (or foreign) words until they hit a match. Some of these programs are so sophisticated that they can attempt over a million combinations per minute.

For tips on good passwords and other security measures, go to www.microsoft.com/security/

Passwords: https://support.google.com/accounts/answer/32040?hl=en

In closing, your best and easiest defense against identity theft is to keep financial information and passwords, as much as possible, stored on an older computer (if you have one) that is not connected to the internet. Furthermore, it is ill-advised to allow Yahoo, for instance, to save your password for you. Although it is probably fairly safe, from time to time you will hear of breaches in security even with a major site such as Yahoo. This is not to single out Yahoo, because this applies equally to Google, Hotmail, even online banking and others.

One final bit of advice is to use sites beginning with 'https' as much as possible when dealing with personal information, while they are fairly secure, as it is widely known that taking risks with your info through regular 'http' sites is a common source of identity theft over the internet.

Pages
Pages | Source

Creating a Text Document with Pages

The Essentials

As Pages is a relatively new application, there is a scarcity of good scripts for it. It is, in fact, very scriptable and while Pages is somewhat akin to AppleWorks, its syntax differs significantly.

Here is a script that I wrote that covers a lot of the essentials:

set documentDate to date string of (current date)
tell application "Pages"
	activate
	make new document
	tell body text of document 1
		set paragraph 1 to documentDate & return & return
		set paragraph 3 to "Dan Peterson" & return
		set paragraph 4 to "4378 W Peach St" & return
		set paragraph 5 to "Chicago, Illinois 60606" & return & return
		set paragraph 7 to "Dear Paul," & return & return
		make new text at after paragraph 8 with data "This is the first paragraph of this document. The font will be changed to 'Courier New' and its size to 14 further down in this script." & return & return
		make new text at after paragraph 10 with data "This is the second paragraph of this document."
		set font name of every text to "Courier New"
		set font size of every text to 14
		set bold of paragraphs 3 thru 5 to true
	end tell
end tell

This is pretty straightforward, but if you have any questions on this or any other AppleScript issue, contact me in the comments section at the bottom of this page and try to be as specific as possible.

Using AppleScript to Create a new Database with Database Events

A little known, but very useful part of MacOS X which has been around now since the release of Tiger (OS 10.4), Database Events is a great app that is very scriptable.

Below is a script which creates and saves a database whose data can be accessed cross-platform through SQLite 3:

display dialog "Enter a name for new database:" default answer "" buttons "Create" default button 1 with icon 1
set databaseName to text returned of the result
set fileDestination to choose folder with prompt "Choose a destination folder for new database:"
set databaseInfo to {{"Jennifer Valdes", "1120 Sequoia Ln", "Cupertino, CA 95014"}, {"James Banks", "345 Iroquois Blvd", "Chicago, IL 60610"}, {"Paul Thompson", "3098 Hampton Ave NE", "Boston, MA 02201"}}
tell application "Database Events"
	launch
	set quit delay to 300
	set newDatabase to (make new database with properties {name:databaseName, location:fileDestination})
	tell newDatabase
		repeat with theContact from 1 to length of databaseInfo
			set theInfo to item theContact of databaseInfo
			set newRecord to make new record with properties {name:item 1 of theInfo}
			tell newRecord
				make new field with properties {name:"Address", value:item 2 of theInfo}
				make new field with properties {name:"cityStateZip", value:item 3 of theInfo}
			end tell
		end repeat
	end tell
	close database 1 saving yes
end tell

After setting the name for the new database and its destination folder, databaseInfo saves the data for 3 records (referenced as newRecord in the repeat loop), as a list.

Note that the data for each record is separated with curly braces and the entire data of databaseInfo is enclosed by curly braces itself to separate one records data from another.

Finally, the database is closed and saved by:

close database 1 saving yes

© 2013 AppleScripter

More by this Author


Comments, Suggestions and Bugs:

No comments yet.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working