Need help with lua script to start Photoshop.

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
JeremyLavine
Posts: 14
Joined: Mon Feb 24, 2014 7:32 pm

Need help with lua script to start Photoshop.

Post by JeremyLavine »

I've been lurking this forum for ages, and it's really been helpful. Anyway I found a script to launch Gimp, but I haven't been able to get it to work with good old Photoshop Elements 5.0, and would really appreciate some help with this.

Here's what I've have:

Code: Select all

-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************

ScriptName = "SP_Photoshop"

-- **************************************************
-- General information about this script
-- **************************************************

SP_Photoshop = {}

function SP_Photoshop:Name()
	return "Photoshop"
end

function SP_Photoshop:Version()
	return "5.0"
end

function SP_Photoshop:Description()
	return "Launch Photoshop application"
end

function SP_Photoshop:Creator()
	return "Simple Scriptor, 2014"
end

function SP_Photoshop:UILabel()
	return("Photoshop")
end


-- **************************************************
-- The guts of this script
-- **************************************************
	function SP_Photoshop.getOS()
	if os.getenv("OS") ~= nil
	then
		local opSys = string.lower(string.sub(os.getenv("OS"), 1, 3))
		if opSys == "win" then
			return "win"
		else
			return "unix"
		end
	else
			return "unix"
	end	
	end

function SP_Photoshop:Run(moho)

 if (moho.layer:LayerType() ~= MOHO.LT_IMAGE)
        then
	LM.GUI.Alert(LM.GUI.ALERT_INFO, "This Script only works with Image Layers.", nil, nil, "OK", nil, nil)
        return
        end
	  
moho:LayerAsImage(moho.layer)
        
image = (moho.layer:SourceImage())
 
 if(SP_Photoshop.getOS()=="win") then
  os.execute(' "Photoshop" "C:\Program Files (x86)\Adobe\Photoshop Elements 5.0\PhotoshopElementsEditor.exe" ' .. '"' .. image .. '"')  --WINDOWS - EDIT path to Photoshop according to your system.
 else
 os.execute("Photoshop" .. image .."&")  --LINUX & Mac - edit path "Photoshop" if it doesn't work.
 end
 
 
LM.GUI.Alert(LM.GUI.ALERT_INFO, "Press 'OK' to reload image when you're done.", nil, nil, "OK", nil, nil)
moho.layer:SetSourceImage(image)
end
Last edited by JeremyLavine on Tue Feb 25, 2014 1:09 pm, edited 1 time in total.
User avatar
synthsin75
Posts: 10013
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Need help with lua script to start Photoshop.

Post by synthsin75 »

I actually rewrote that Gimp script for PSE3 ages ago (should be an easy enough change to PSE5). All my old links to the script are dead, so give me some time to find it and repost it.
User avatar
JeremyLavine
Posts: 14
Joined: Mon Feb 24, 2014 7:32 pm

Re: Need help with lua script to start Photoshop.

Post by JeremyLavine »

Hi synthsin75,

I've updated the script again since I noticed it referenced another by mistake, but it only works partially. When I start the script after selecting an image all I get is a pop-up stating "Press 'OK' to reload image when you'e done", but Photoshop still doesn't start.

I hope what you have works with PSE5. Does it also work with images within a switch?
User avatar
synthsin75
Posts: 10013
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Need help with lua script to start Photoshop.

Post by synthsin75 »

Here you go:
http://www.filedropper.com/dreditinpse

You'll have to change the path to reflect PSE5.

This should work with any selected image layer.
User avatar
JeremyLavine
Posts: 14
Joined: Mon Feb 24, 2014 7:32 pm

Re: Need help with lua script to start Photoshop.

Post by JeremyLavine »

Thanks, synthsin75!

Your script works like a charm with PSE5! Gonna save me hours! :D
User avatar
synthsin75
Posts: 10013
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Need help with lua script to start Photoshop.

Post by synthsin75 »

Glad I could help.
User avatar
Lukas
Posts: 1300
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Need help with lua script to start Photoshop.

Post by Lukas »

Synthsyn75, do you know how to get this to work with Photoshop CC on OS X?
User avatar
synthsin75
Posts: 10013
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Need help with lua script to start Photoshop.

Post by synthsin75 »

I've never worked with Macs, so I'm not sure what the exact path would be or how the image file would be provided as an argument for PS to open. It should certainly be possible though. Vern uses Macs, so may be he'd be willing to help.
gvboy
Posts: 2
Joined: Sat Sep 15, 2012 12:11 am

Re: Need help with lua script to start Photoshop.

Post by gvboy »

Using the modified code below worked for me on Mac... just need to edit the actual app name of your version of photoshop (mine is "Adobe Photoshop CS5")

Hope this helps.

Code: Select all

else
 os.execute('open -a "Adobe Photoshop CS5" ' .. image)  -- for MAC- Edit Photoshop App name
 end
User avatar
Lukas
Posts: 1300
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Need help with lua script to start Photoshop.

Post by Lukas »

gvboy wrote:Using the modified code below worked for me on Mac... just need to edit the actual app name of your version of photoshop (mine is "Adobe Photoshop CS5")

Hope this helps.

Code: Select all

else
 os.execute('open -a "Adobe Photoshop CS5" ' .. image)  -- for MAC- Edit Photoshop App name
 end
Thanks so much! Finally it works :)
Post Reply