Categories
AppleScript Notes FlickrFan

FlickrFan – find the Mac default pictures folder

sys.UnixShellCommand("osascript -e '(path to pictures folder) as string'")

More better (since you get a newline at the end of the above)
string.trimWhiteSpace(sys.unixShellCommand("osascript -e '(path to pictures folder) as string'"))

The list of possible “magic” folders in AppleScript

Get multiple folder paths in one swell foop

osascript -e '{(path to pictures folder) as string, (path to applications folder) as string}'

returns a comma-separated list.

Categories
AppleScript Notes FlickrFan

Applescript – path to

The path to command now has the following new folder constants:

  • applications folder
  • documents folder
  • favorites folder
  • home folder
  • library folder
  • movies folder
  • music folder
  • pictures folder
  • public folder
  • shared documents
  • shared documents folder
  • sites folder
  • utilities folder

From the Applescript folks…

An additional tip about “path to”: you don’t need to wait for us to add an
explicit enumeration, since it can also take any four-character string that’s a
FindFolder selector. Get your hands on a copy of Folders.h (part of the Master
Interfaces) and go nuts.

Look here

/Developer/SDKs/MacOSX10.4u.sdk/Developer/Headers/CFMCarbon/CarbonCore/Folders.h

Categories
AppleScript Notes

Application Keywords in Applescript

A modest solution would be to improve AS’s pretty printer so it
uses different styles to distinguish between commands, properties,
elements, types and enums, rather than using a single style for all
as it currently does. If anyone wants to file a feature request to
that effect then be my guest.

Something you can do right now (thank you for the perfect segue) is
to change the style for application keywords to be underlined.
Because it will also underline the space, you can tell, for example,
that “path to” is a single term, while “path of” is two. (I did this
a while ago while tracking down a terminology bug, and discovered it
was generally useful.) However, has’ idea is still a good one.

–Chris Nebel
AppleScript and Automator Engineering

[1] How to do it:

Categories
AppleScript Notes

Random in Applescript

a demonstration of random numbers and random letters – note “some”


set x to {}
repeat (random number from 8 to 10) times
set end of x to some item of "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
end repeat
x as text --> "JUEQPJBH", "LFOBPXHJI", "TQRVYJPHFA"

Categories
AppleScript Notes System Software Notes

macosxhints – A shell/AppleScript interaction trick

macosxhints – A shell/AppleScript interaction trick
However, there is a convention in unix that executable files that do not have a recognizable header (of which #! is one) are passed to /bin/sh for execution. This allows considerable flexibility for use with AppleScript. The most basic idea is to use a first line containing:

Categories
AppleScript Notes

do shell script

do shell script in AppleScript

This Technote answers frequently asked questions about AppleScript’s do shell script command, which was introduced in AppleScript 1.8

Can’t have enough links to this document

Categories
AppleScript Notes

Writing a Decent Bug

As long as we’re on the topic, I should reiterate some of the
guidelines for writing a decent bug. (Violating them will tend to get
your bug bounced back to you or sent to the back of the queue.)

1. File a bug on a specific issue. A bug on a 100-line script that
“doesn’t work” is not specific. A bug on three different problems that
you happened to hit on the same day is also not specific. (In that
case, file three bugs. If you find yourself typing “by the way” or
“while I’ve got your attention,” you’re probably breaking this
guideline.)
2. Use an informative title. “Getting item 0 of a list crashes” is an
informative title. “AppleScript is broken” is not.
3. Read the problem template and follow its instructions. If you don’t
have anything new to say in a section (for example, Notes), delete it.
Always delete the instructional text.
4. Try to reproduce the problem in the fewest steps possible. Short
scripts are better than long scripts.
5. Describe both what did happen and what you expected to happen.
6. Include the OS version, and the application version if applicable.
7. Don’t editorialize. Think Joe Friday: just the facts.
8. Don’t diagnose. That’s our job.

Also, just because it’s “Bug” Reporter doesn’t mean you can’t file
enhancement requests — just check the “enhancement request” checkbox.

–Chris Nebel
Apple Development Tools

Categories
AppleScript Notes

path to over eppc

Date: Mon, 9 Jun 2003 10:39:58 -0700
Subject: Re: path to over eppc?
Cc: applescript-users@lists.apple.com
To: matt neuburg
From: Christopher Nebel

On Sunday, June 8, 2003, at 07:19 PM, matt neuburg wrote:

>The status of the phrases “beep” and “say” and “display dialog” and
>”path to” is the same – they are all scripting addition commands. But
>in the following script:
>
>tell app “Finder” of machine “eppc://little-white-duck.local”
> beep
> say “howdy”
> display dialog “howdy”
> path to system folder
>end
>
>the first three commands are executed on the remote machine, but “path
>to” is executed on the local machine. I need to know why. Please note,
>I don’t want a workaround; I want an explanation.

That’s no bug — that’s a feature! Well, sort of. Here’s what’s going
on: “path to” really is being executed on the remote machine. The
tricky bit is that “path to” returns an alias — an alias, that is,
that points to something on a remote machine’s disk that the local
script can’t see! When AppleScript tries to display the alias as a
full path, the Alias Manager, in a desperate attempt to produce
something “useful,” substitutes the local disk name for the remote disk
name, comes up with a valid path, says aha! and hands it back to you.
(If I remember right, QuickTime added that little stunt back around Mac
OS 8.6 or so. Something about making otherwise broken aliases resolve
more often.)

The upshot is that aliases aren’t entirely meaningful over eppc, since
files visible on one side aren’t visible on the other. (It should work
if you take the resulting alias and hand it back to the remote side;
you just can’t inspect the alias locally.) If you say “path to … as
string”, you’ll see the correct remote path.

–Chris Nebel
Apple Development Tools

Categories
AppleScript Notes

Quoted form of POSIX path

POSIX path of (choose folder) –> /Users/someUser/Desktop/Virex Reports/

This can be overcome by using ‘quoted form of POSIX path’.

quoted form of POSIX path of (choose folder) –> ‘/Users/someUser/Desktop/Virex Reports/’

Look at POSIX file ‘/Applications’ as alias

Categories
AppleScript Notes

See if an application is running

tell application “Finder” to set itStatus to exists process “iTunes”

This will fail if the app name is different, which is common (on a mac it is usually a Bad Thing to rely on names or paths). I would rather use the creator code (“hook” in iTunes’ case):

tell application “Finder” to set itStatus to (“hook” is in creator type of every process) –> returns true if iTunes is running

If you don’t know the signature of your app, ask for it:

tell application “Finder” to return creator type of process “theApp” –> returns theApp’s creator code if it is currently running