I am an applescript novice who has occasionally used the language since OS 9. I’ve always been able to figure out how to achieve my desired results but I am running into a wall now and would like to see if anyone would be able to help.
I am trying to write a script that will display a dialog box when I open a file on my computer that is a certain type (be it .xlx, .ppt, .doc, etc.)
Any guidance here would be much appreciated, thanks in advance!
Drag and drop the file’s icon upon an applet’s icon which will do the wanted job.
Here is the applet’s code :
on open (sel)
local thefile, theExt
set thefile to item 1 of sel
tell application "Finder" to set theExt to name extension of thefile
if theExt is in {"xls", "ppt", "doc"} then
display dialog "got one of the selected kind of files"
end if
tell application "Finder" to open thefile
end open
Again, thanks for the quick reply. I’ll let you know what I come up with if I’m able to pull this off. I’ve looked into a watch script that checks in periodically to see if certain files are open. I’ll have to implement this and see if it causes performance issues and is responsive.
You could try writing an Applescript application that does two things:
displays the dialog box
opens the document in the usual application (Word, Excel, etc.)
and then set your script as the default application for the file type (.doc, etc.) by selecting a .doc file, using Get Info, Open With, Change All, and navigating to your script.
I haven’t tried this specific route, but it should probably work. You may need to modify the info.plist file of the AppleScript application so that the application is recognized as a handler for the file type. Look into existing info.plist files to see how it’s done.