def start(): # Defining necessary variables app = GetActiveObject("Photoshop.Application") psApp = win32com.client.Dispatch("Photoshop.Application") doc = psApp.Application.ActiveDocument docRef = app.ActiveDocument # Logs the current layer previousLayer = docRef.activeLayer.name # Logs the current tool with Session() as ps: tool = ps.app.currentTool # Goes to the top most layer docRef.ActiveLayer = docRef.Layers.Item(1) # Plays the action "Magic Wand for Selection Script" in group "Selection Script Group" in the Actions panel # Sets the tool to Magic Wand app.DoAction('Magic Wand for Selection Script', 'Selection Script Group') # Waits for the left click # If it a mouse click that is not the left mouse button, does nothing def on_click(x, y, button, pressed): while button == mouse.Button.left: return False with Listener(on_click=on_click) as listener: listener.join() # After left click, sets the tool as the the tool that was selected previously ps.app.currentTool = tool # Goes to the layer that was previously active docRef.ActiveLayer = doc.ArtLayers[previousLayer]
# This script demonstrates how to use the action manager to execute a # previously defined action liek the default actions that ships with Photoshop # Or one that you've created yourself. The name of the action comes from # Photoshop's Actions Palette from win32com.client import Dispatch, GetActiveObject, GetObject # Start up Photoshop application # Or get Reference to already running Photoshop application instance # app = Dispatch('Photoshop.Application') app = GetActiveObject("Photoshop.Application") fileName = "C:\Git\photoshop-scripting-python\PS_Samples_Files\Layer Comps.psd" docRef = app.Open(fileName) app.DoAction('Molten Lead', 'Default Actions')