Changing default application

I used to be able to change the default application for files through AppleScript, by changing Creator Type in the Finder. This doesn’t seem to do the job anymore. Even though

Tell application "Finder"
set creator type of this_file to "MAXm"
end tell

does apparently change the TIFF file’s creator, it still wants to open with Preview instead of the editor I need to use it with.

I tried to change both default application and kind but got no more joy:

tell application "Finder"
set kind of this_file to "PaperPort Page Viewer Document"
				--error: "NSInternalScriptError"
end tell

Looking in the dictionary, it looks as if both Creator Type, Kind and Default Application are read-only.

I’ve been scripting for years, and every once in a while scripts stop working, usually because of system/AppleScript/dictionary changes.

Anyone have a clue on this one? didn’t find any hints in the archives.

Model: G4 dual 450
AppleScript: 1.10.7
Browser: Safari 525.22
Operating System: Mac OS X (10.4)

Changing the creator works fine for me… (Leopard and worked under TIger, as well). Maybe you defined “Preview” as the default app for your TIFF files? (using the Finder’s get-info window) If so, you may need alther the LaunchServices plist file (and delete the entry regarding TIFF files) before trying to use the “creator type” hack.

try a droplet…

on open these_items
	tell application "Finder"
		repeat with this_item in these_items
			open this_item using application file id "MAXm"
		end repeat
	end tell
end open

Tom

Browser: Safari 528.1
Operating System: Mac OS X (10.5)

To Julio:

Thanks for your response. Preview is default OSX app of choice, I guess, but as a designer, I open files with GraphicConverter, Photoshop, PaperPort Page Viewer (the “MAXm” of the sample script) depending on need; holding the control key offers me probably 30 apps that read tiffs…

In this case, files come in from my scanner to a folder, neatly numbered, and I want to convert them all to open with PPPV on a double-click. I straighten and crop them one at a time, then resave as compressed tiffs for Quark chapters, where I import them ( and size and scale and position them) folder by folder via AppleScript. In the case of the scripts I tried, AppleScript does report a change of creator, but… the default application doesn’t change to match (though it did when the project came through last year.) It’s not that I can’t do it some other way, but I only make money with an optimized workflow, which AppleScript definitely offers (at least when I get it up and running. Every year I seem to do a little updating and re-tweaking…)

I used to be able to shift-select a folder’s worth of files in the Finder, “Get Info” and change the default for those files as a group; now it seems that at least half the time I get a Get Info window for each file. (200+ folders, up to 35 files per folder, not a fun route). Don’t think I’m doing anything different each time, and I have tried different key combinations, different ways of selection, etc. with same mixed results… no info on this situation on the web, so far as I have found.

My next fall-back is probably to change default for the whole system, then drop back, either when this project is done or when a different project requires Photoshop or Preview or whatever. But I had hoped to have a little more surgical control over which files have their preferences changed.

To Tom:

Thanks for your response, too. Your droplet would be great as is, IF I needed to open them all at once. However, since I need to do surgery on each, then Resave As (and in a Classic Ap at that!) I may modify it so that I can drop each file on it as needed. No creator change, or whatever, but I get it open without having to scroll down through 30 or so available apps when I hold the control key.

So though “you can’t always get what you want, if you try sometimes … you can get what you need.” I’ll give it a try and report back.

To everyone:
If anyone has any insight on controls for “open with app X” by default, I’m still interested.

Thanks to all
George

Model: G4 dual 450
AppleScript: 1.10.7
Browser: Safari 525.22
Operating System: Mac OS X (10.4)

Buenas tardes Julio

It doesn’t help George, but Leopard introduces a default application property of each file element in System Events

Thanks Stefan.

I have tried to affect that property. My Script Editor shows the dictionary listing default application as r/o, which doesn’t offer much hope… and if this is new, perhaps that is why the older scripts have stopped working… (Getting used to this, if not quite reconciled … my scripts go back to Quark 3 or so… System 6 or 7.)

Thanks again – and still listening for new information if anyone has any.

George

No, the property default application of class file is get/set, this works


tell application "System Events"
	set default application of file "Path:To:File.jpg" to (path to application "Preview")
end tell

With high hopes, I put together this script:


on changeDApp(these_items)
	tell application "System Events"
		repeat with this_item in these_items
			set default application of this_item to (path to application "PaperPort Page Viewer")
		end repeat
	end tell
end changeDApp

on run {}
	tell application "Finder"
		set This_folder to (choose folder with prompt "Set default app to Page Viewer for which folder of scans?")
		set these_items to every file of This_folder
		my changeDApp(these_items)
	end tell
end run

BUT I got this error result:

Can’t set default application of document file “FinlandE-001.tif” of folder “FinlandE” of folder “External” of folder “08SSB Legal” of folder “Desktop” of folder “George” of folder “Users” of startup disk to alias “Speedy Gonzales9:Applications (MacOS9):Utilities:PaperPort 5.0 Folder:PaperPort Page Viewer”.

Not quite sure what is going on, but I’d sure like to know…

George

Model: G4 dual 450
AppleScript: 1.10.7
Browser: Safari 525.22
Operating System: Mac OS X (10.4)

Alternate version:


on run {}
	tell application "Finder"
		set This_folder to (choose folder with prompt "Set default app to Page Viewer for which folder of scans?")
		set these_items to every file of This_folder
		tell application "System Events"
			repeat with this_item in these_items
				set default application of this_item to (path to application "PaperPort Page Viewer")
			end repeat
		end tell
	end tell
end run

result:
Finder got an error: Can’t set default application of document file “FinlandE-001.tif” of folder “FinlandE” of folder “External” of folder “08SSB Legal” of folder “Desktop” of folder “George” of folder “Users” of startup disk to alias “Speedy Gonzales9:Applications (MacOS9):Utilities:PaperPort 5.0 Folder:PaperPort Page Viewer”.

I assume, you work on Leopard anyway, it doesn’t work in Tiger :wink:

the dictionaries of Finder and System Events are quite similar, but not the same.
You pass a list of Finder file specifier to the handler, which don’t have a default application property

try this


on changeDApp(these_items)
	tell application "System Events"
		repeat with this_item in these_items
			set default application of file (this_item as text) to (path to application "PaperPort Page Viewer")
		end repeat
	end tell
end changeDApp

StefanK

I just noticed the “(this_item as text)” clause in your last post and decided to hack my last posted try to see if it was a reference issue.

My error message says

Can’t set default application of “XMen1:Users:George:Desktop:08SSB Legal:External:PeruE:PeruE-001.tif” to alias “Speedy Gonzales9:Applications (MacOS9):Utilities:PaperPort 5.0 Folder:PaperPort Page Viewer”

But I should note that the drag-n-drop “open with” script provided earlier by Tom_X works fine one file at a time, so it will probably serve my needs as well as a double-click solution would, if I can keep the script visible on my desktop… So even if, ideally, I’d like to generate a recursive script to change the several-thousand files at a pass, I can maintain reasonable productivity in spite of the recalcitrance of this default application property!

But if any other ideas come up, I’d still like to try them out. (Maybe once I get beyond this project, I’ll be ready to move onward to new system software, but I’ve learned not to get too adventurous in the middle of a large scripted project, or I’ll be squashing bugs instead of turning out billable hours…)

Best wishes to all
George

wasn’t it easier, to put all files into one folder, then open the folder and press ⌘A ⌥⌘I in the Finder and change the default application all at once.
I guess the problems come from some pre OS X format of the files.

Hi Stefan

Incoming format is straight tiff from the Epson scanner, running under OSX, so I don’t think it’s that.

I don’t know why, but when I try to change the creators for a block of files, I have been getting individual windows for Get Info at least half of the time, which makes it tedious to change creators that way. Don’t know why it happens so sporadically.

And with perhaps a thousand files in all, putting them back into their respective folders would be more work than changing them a folder at a time. (Scripting downstream uses folder names to create chapters, adjust footers, etc.)

But if dropping the files one at a time to open them in the appropriate app works, that’s sufficiently streamlined to keep me efficient in this project. (I realized last night I could probably have put an alias of the app on the desktop and dropped files on that to open them. “When a boy has a hammer, everything looks like a nail.”;))

Best wishes
George

I was confused by the path “Speedy Gonzales9:Applications (MacOS9):Utilities:” and assumed you’re talking about a classic application

But I don’t understand, why setting default application in Leopard and setting file type or creator type in Tiger doesn’t work.
All properties can be set and get

creator type get/set type class the OSType identifying the application that created the item
file type get/set type class the OSType identifying the type of data contained in the item

Maybe your current account is a managed account without administrator privileges.

No, I’m administrator on this machine, both root and user levels.

my System Event library (system X10.4, AS 1.10.7) shows

file‚n [inh. disk item > item] : A file in the file system

properties
creator type (Unicode text) : the OSType identifying the application that created the file
file type (Unicode text) : the OSType identifying the type of data contained in the file
kind (Unicode text, r/o) : The kind of file, as shown in Finder

My Finder library shows

file‚n [inh. item] : every file

properties
file type (type class) : the OSType identifying the type of data contained in the item
creator type (type class) : the OSType identifying the application that created the item

and Standard Additions library shows

default application (alias, r/o) : the application that normally opens this kind of item

so it is true that creator type and file type are settable (and a dowser script that asks for creator type and file type does report the changes); but apparently that is (maybe no longer) enough to get the file launched by its creator.

Is a puzzlement. :frowning:

George

Let me repeat that I always talked about default application of System Events (not of Standard Additions), with is only available in 10.5 LEOPARD

Maybe this could be a way

from StefanK

I do appreciate that you were discussing Leopard for default application. (Unfortunately I don’t have that option available at present.) I was just reviewing the only place I saw “default application”. I hope you didn’t take my comment as a criticism or as being unappreciative; I do appreciate the help you and other scripters have extended so freely over the years, and I doubt I would have the knowledge I do without all those many contributors. My comments were intended simply as feedback to the list; I know I always check the archives first, and others may come with similar issues.

For now, I think I will pass on command-line solutions, but I will keep them in mind for when a more “geeky” solution is urgently called for. While I have several years experience with AppleScript, and some with javascript, postscript, Fortran and Basic,etc., I’m not currently ready to learn to stay out of trouble with Unix-based commands; from what I understand, mistakes can be catastropic and irreversible. “A man should know his limitations.”:slight_smile:

I logged in just hoping that some corner of the Applescript world had a workaround for the problem I had (string coercion, or other technical gotchas etc.), but if the System software is stacked against me, that just means I have to do things differently. It wouldn’t be the first time, and I remain appreciative that this technology continues to save me enormous amounts of (very boring) time.

Best wishes
George

I know, that’s why I wrote in my first post

I shouldn’t have done that.:confused:

No worries.

When things don’t behave the way they used to, you don’t always know if you need to do something different or not. As Apple shuffles its system software around, properties seem to move from one “owner” to another, and I have to update scripts accordingly. The thing that got me this time seems to be “default application” which apparently last year (when I was on maybe 10.2 or 10.3?) was extracted from creator but now may not be. Don’t know – that’s just a guess.

Still not as bad as Quark, where I seem to need to debug after every dot upgrade…

George

To finish off this topic, here is final version of script application I’m using, based on Tom_X’s draft. I have it take care of a little bookkeeping while I’m at it. I drop the tiff file onto the icon, it opens, I edit, do a save as with the name which has been loaded in the clipboard. Sometimes with drop-in script forms like this I also add a run handler to peek at the event log in case I have to change anything.


on open these_items
	tell application "Finder"
		repeat with this_item in these_items
			--in most cases, this will be a single item, but it works just as well
			set the clipboard to (name of this_item as string)
			-- saves name of file AS STRING for later "Save As" under classic app
			-- classic apps don't recognize the Unicode text form standard for OSX system names.
			set label index of this_item to "2"
			--marks file Red (processed), in case I am interrupted
			open this_item using application file id "MAXm"
			-- opens file in classic app "PaperPort Page Viewer"
		end repeat
	end tell
end open

Best wishes
George