Changing default application

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

Hi

I am trying to use this thread to make a folder action script that changes the default application for the file to Apple Preview.

I have this:

on adding folder items to this_folder after receiving dropped_items
	set listofextensions to {"pdf", "jpg", "tif", "tiff"}
	tell application "System Events"
		repeat with this_item in dropped_items
			repeat with extcheck in listofextensions
				if (this_item as text) ends with extcheck then
					set default application of file (this_item as text) to (path to application "Preview")
					exit repeat
				end if
			end repeat
		end repeat
	end tell
end adding folder items to

Before I added the test repeat to check what type of file was being dropped into the folder, the default application change worked fine. But of course I do not want all types of file changed to default to Preview. After I added the repeat test, the script fails to work.

Can anyone suggest where I am going wrong?

Thanks

easier


property listofextensions : {"pdf", "jpg", "tif", "tiff"}

on adding folder items to this_folder after receiving dropped_items
	tell application "System Events"
		repeat with this_item in dropped_items
			if name extension of this_item is in listofextensions then
				set default application of file (this_item as text) to (path to application "Preview")
			end if
		end repeat
	end tell
end adding folder items to

I’m a little confused by this thread…

I write a script (Clorox File Repair) that restores the File Type and File Creator of files that lose their resource fork, usually from landing on a PC without an AppleTalk stack, or from being compressed into things like TAR. This is the behavior the OS exhibits in my experience when missing File Type and File Creator:

–Tries to use the file extension as a basis to guess what app to use, then uses the “Open with” defaults
–Without extension, the Mac OS seems to have some limited ability to peek inside a file’s header to take a guess.

Problem is, it’s a lousy guesser at both. For example, all “EPS” files must be Photoshop files…couldn’t be Illustrator after all. :wink:

So Clorox File Repair uses hard-coded detection routines that are more accurate, and when it fixes File Type, Creator, and sometimes the extension, the Mac OS wil treat the file as such:

–If the Creator is available, launch that application
–If the Creator is unknown, use the “Open with” choice

So by all that I know, simpy changing the Creator Type should fix the problem of the OP unless I misread. In other words, write a script that changes the Creator Type and double-click to your heart’s content.

Is this not 100% true in Leopard anymore and somehow I’ve just randomly avoided the issue?

Otherwise using “set creator type of to <4 character creator code> as text” solves the problem handily…

[confused]

Stefan

Many thanks. Works well. Although I am a little suspicious of Folder Action Scripts as I find them to be erratic in real time operation. Still, while it works:)…

Merci

You can test Folder Action scripts by commenting out the event handler lines
and adding a line to specify the files. Then you get error messages, if something fails


property listofextensions : {"pdf", "jpg", "tif", "tiff"}

set dropped_items to choose file with multiple selections allowed
-- on adding folder items to this_folder after receiving dropped_items
tell application "System Events"
	repeat with this_item in dropped_items
		if name extension of this_item is in listofextensions then
			set default application of file (this_item as text) to (path to application "Preview")
		end if
	end repeat
end tell
-- end adding folder items to