Default Application

Is it possible to change the default application with an Applescript?

I'm trying:
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #E6E6EE;
overflow: auto;">
tell application "System Events"
set default application of (POSIX file "/Users/Tony/Documents/filename.aes" as string) to alias ("Macintosh HD:Users:Tony:Library:Scripts:DecryptAES256.app:")
end tell</pre>

but get the error:

<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #E6E6EE;
overflow: auto;">
Can’t set default application of "Macintosh HD:Users:Tony:Documents:Web Receipts:filename.aes" to alias "Macintosh HD:Users:Tony:Library:Scripts:DecryptAES256.app:".</pre>

MacBook /, Mac OS X (10.6.4), / Windows xp (Boot Camp)

Posted on Sep 29, 2010 10:19 AM

Reply
4 replies

Sep 29, 2010 4:23 PM in response to Tony T1

You were close - default application is a property of a file. *System Events* will accept text paths (Finder or POSIX), but can get a bit finicky with aliases. It also seems to be more finicky than most if sending it commands from scripting additions (e.g. POSIX file).
set theFile to "/Users/Tony/Documents/filename.aes"
set myApp to (path to application "DecryptAES256") -- can also use bundle identifiers
tell application "System Events" to set default application of file theFile to myApp

Sep 29, 2010 5:26 PM in response to Tony T1

You probably don't have the Info.plist file set up the way the OS likes it, so the path to application isn't working correctly. If you set your default application directly, it should work OK (it seems to work on my machine anyway):
set theFile to "/Users/Tony/Documents/filename.aes"
set myApp to alias "Macintosh HD:Users:Tony:Library:Scripts:DecryptAES256.app:"
tell application "System Events" to set default application of file theFile to myApp

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Default Application

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.