still trying to figure out paths

Hi,

I am having trouble getting my head around paths to files on unknown machines.

As a POSIX statement I can use things like

/private/etc/log/somefile

or

$HOME/Preferences/somefile

but how can I do that in AppleScript lingo? If I use the Applescript standard additions dictionary ‘POSIX’ class it converts the POSIX path to AS path upon compiling so that

set my_file to POSIX file "/private/etc/log/somefile"

becomes

set my_file to file ":MYHARDDRIVE:private:etc:log:somefile

This works locally but not generically as the POSIX path would. Any help would be greatly appreciated.

TIA, jim

Just place your path into a variable and then use the “POSIX file” command:

Jon


[This script was automatically tagged for color coded syntax by Script to Markup Code]

Thanks, jonn8 - makes sense.

How can I use it in the next line . . .


set path_to_file to "/private/var/log/some.log"
set file_results to POSIX file path_to_file
set contents of text field "textdisplayed" to (modification date of (info for file_results)) as date

Thanks, Jim

Perhaps this should be in the AppleScript Studio Forum…

Try coercing the date to a string (and also make sure you are either inside a tell block for the container or that the container is explicitly enumerated as in the following code):

Jon


[This script was automatically tagged for color coded syntax by Script to Markup Code]

I just tried a bare test project . . . one window with one text field. The text field has a ‘on wake from nib’ handler and the as name “date_result”. I keep getting the Applescript error (10)

Thanks, jonn8

In your “path_to_file” declaration it looks like you are missing the first forward slash.

You can also take a look at this project: Spinner.hqx.

Jon

That Spinner project will give me lots to digest - thank you.

one question about that. What is the purpose of this format that you use with all the handlers? i can’t seem to find any documentation of that type of construct.

on choose menu item the_object
	set object_name to name of the_object as string
	my update_status("choose menu item " & object_name)

I use this so that I can log what is going on.

on choose menu item the_object
Or any action.

set object_name to name of the_object as string
Get the object’s name so I can test for what to do when the object is acted on.

my update_status("choose menu item " & object_name)
This is a handler I’ve written (see the bottom of the main script of the project). All this does is log whatever parameter is passed to it. I use this instead of individual log items so that if I want to turn off logging, I only have to modify the “update_status” handler to comment out the log command. In many of my scripts I log when an action is received, when data is returned, when there are errors, when an action is completed, etc. If I want to turn off logging, it is a pain to modify all of these log calls so I use this handler instead.

I’ve tweaked my default AS Studio application templates (Macintosh HD:Developer:ProjectBuilder Extras:Project Templates:Application:AppleScript Application:) to automatically add an “about” window to the NIB (as well as a progress, pref, and main windows) plus a bunch of useful default subroutines in the main AppleScript, and even the default plist so it uses my preferred version and copyright info. You can also set the default AppleScript names and properties for the elements in your NIB but you’ll have to manually check the default script to connect them all after your new project is built. All in all, though, this saves a huge amount of time when creating new projects. The “update_status” is part of this default project. If you modify your default templates, you should make a duplicate first and save that in a safe place. Also, after modifying your project template (which you do just like working with any other project) you should delete the “build” folder when you’re done so it doesn’t get copied to your new projects based on this template.

Jon