PDA

View Full Version : Can this be done with Applescript?




floyde
May 29, 2006, 10:25 AM
Hi, I was wondering if the following can be achieved using Applescript:

I want to have Safari launch jpg images in Photoshop instead of having these images displayed on the browser window. Of course I don't intend for Safari to have this behavior with every image it displays (ie <img> tags) just with images that are accessed via a link, such as <a href="someimage.jpg">Download image</a>. I know this sounds bizarre, but it's a requirement for a web application we're developing here at work.

I hope this is not too confusing, basically, what I want is something similar to launching a .pdf in adobe reader instead of using the built-in pdf plugin in Safari. I know IE5 Mac and Opera can be configured to allow this behaviour with several mime types, but Safari doesn't seem to have that feature... So, can it be done with Applescript? And if so, could someone give me the basics of how it could be done? thanks



robbieduncan
May 29, 2006, 11:38 AM
Applescript cannot change the behaviour of apps like this, only control the existing behaviour.

You could achieve this via a SIMBL plugin (http://www.culater.net/wiki/moin.cgi/CocoaReverseEngineering) but you will be relying on the plugin being installed on the client machine which is probably a bit dodgy.

If you can rely on installing something on the client machine you could write a Safari plugin to implement a URL handler to allow you do do something like <a href="photoshop://www.myserver.com/myimage.jpeg>text</a> but this may be outside the scope of your project.

floyde
May 29, 2006, 12:16 PM
Applescript cannot change the behaviour of apps like this, only control the existing behaviour.
Well, I was thinking that maybe I could have a script running in the background, waiting for the user to click on a link that has a URL that ends with ".jpg". I don't know if that's possible, but I found a script (http://www.apple.com/applescript/safari/) (Open Linked Images) that could potentially open images in Photoshop, but it would need to be run by the user at the proper time, so it might not be the best idea (unless I can make it run in the background without requiring any user interaction).


If you can rely on installing something on the client machine you could write a Safari plugin to implement a URL handler to allow you do do something like <a href="photoshop://www.myserver.com/myimage.jpeg>text</a> but this may be outside the scope of your project.

I guess if there's no other choice, the client might want for us to do something like that. The problem is that the app was already working under IE5 Mac, which has a feature that lets you associate a .jpg with an application. So the "opening jpegs in Photoshop" feature is already there, and I don't think they'll want to give it up. Do you think writing a plugin like that would take a long time? I've never developed anything for Mac (the app was coded in ASP .NET even though 90% of the users use Macs, and I still can't understand why they didn't use something more Mac-like :eek: :D ), so I guess I'd have to learn some Objective C? thx

robbieduncan
May 29, 2006, 12:39 PM
I have no experience of developing plugins to do this sort of thing. If you can find a developer with the appropriate experience then it does not appear to be too difficult to have this done, but I am talking from a position of ignorance!

floyde
May 29, 2006, 03:05 PM
If you can find a developer with the appropriate experience
There aren't (m)any of those where I live. In fact, I'm pretty much the "Mac expert" around here :p .

Anyway, I'm now able to open image URL's in Photoshop using Applescript. Is there a way to know when the user clicks on a link in Safari? or perhaps a way to execute an Applescript by clicking on a link? (I know it's unlikely, but you never know ;) ) If I could do that then my problem would be solved.

robbieduncan
May 29, 2006, 03:11 PM
Note that's what you'd need the plugin for :D

You might be able to get some sort of strange Javascript thing going that then calls out to Applescript somehow...

Soulstorm
May 29, 2006, 03:32 PM
Hi, I was wondering if the following can be achieved using Applescript:

I want to have Safari launch jpg images in Photoshop instead of having these images displayed on the browser window. Of course I don't intend for Safari to have this behavior with every image it displays (ie <img> tags) just with images that are accessed via a link, such as <a href="someimage.jpg">Download image</a>. I know this sounds bizarre, but it's a requirement for a web application we're developing here at work.

I hope this is not too confusing, basically, what I want is something similar to launching a .pdf in adobe reader instead of using the built-in pdf plugin in Safari. I know IE5 Mac and Opera can be configured to allow this behaviour with several mime types, but Safari doesn't seem to have that feature... So, can it be done with Applescript? And if so, could someone give me the basics of how it could be done? thanks
You could do that if that was a feature of safari. Go to the application's dictionary for applescript (you can do this via script editor) and see if there's a feature like this in it... but I doubt it. Anyway, maybe you could do this another way:

The only thing you need to do is to open an image to Photoshop. So, you need a way to extract the image's location from the internet. So, with a script, you can tell Safari to download temporarily a specific image to the desktop, and from there, tell Photoshop to open that image. If you want to open specific images (with '<a href>') you will be able to do so, by writing routines that access the source. If I recall correctly, last time I checked applescript's documentation for OS X, safari has a specific command to access the source of a webpage, as well as predefined classes to describe properties of each element in a browser window, only that I don't know if the concern the UI or the contents of the page itself. To find that out, you must write some test programs.

So, in short talk: Yes, you can certainly do this using applescript, only that you will need to work a little harder than you thought, and you may not have the time to learn the language well enough to do so.

I think I told you how to create your program... It has been long since I have developed anything using applescript... Those were the days... (I was 15 then)

floyde
May 29, 2006, 05:42 PM
If I recall correctly, last time I checked applescript's documentation for OS X, safari has a specific command to access the source of a webpage, as well as predefined classes to describe properties of each element in a browser window, only that I don't know if the concern the UI or the contents of the page itself. To find that out, you must write some test programs.
Thanks, I've managed to get the image URLs and open them in Photoshop, but I don't think there's a way to call an Applescript from a webpage in Safari. So I decided to check out some docs on webkit plugins and they seem really simple. The samples are only a few lines long, and I'm sure that the plugin I need would be even shorter, but out of a few lines I understood exactly: 0 :o (Objective-c is a bit strange).

Anyway, I'll do a quick test (according to my theory, all I need to do is call the applescript I already made on the plugin's constructor and voilà!) and if it doesn't work I don't think I'll spend anymore time with this. The most likely scenario is that we'll delay the Safari migration a bit longer.

floyde
May 30, 2006, 11:19 AM
Another reason to love Apple: I opened the WebKitMoviePlugin sample, added 3 lines of code, and now I have a WebKit plugin that launches the Applescript when called by a Javascript function! It was that easy!

Well, in reality, I spent a few hours on this (I had to do some Objective-C research), and I still need to write the plugin from scratch (I'm not using some sample code on my project!), but still, it was much easier than I thought it'd be.

see.solve.
Mar 5, 2013, 03:11 AM
For others who might be looking for similar functionality, it's been a while since I took Choosy (http://www.choosyosx.com/) for a test drive, but I believe it might be able to do what you require.