Python Forum
Python Script to repeat Photoshop action in folders and subfolders
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Script to repeat Photoshop action in folders and subfolders
#1
Hello.

I am using Windows 7, Python 3.6, editor Pycharm.

My goal :
Apply recorded action in Photoshop to many folders and subfolders containing images

My inspiration :
https://vsfxryan.com/portfolio/python-ph...n-scripts/, although I would not like to use function definitions in my code, because I do not know how to do it.

My code :
import os
import shutil
import win32com.client

psApp = win32com.client.Dispatch("Photoshop.Application")

input_1 = "location input 1"
output = "location output"

for src_dir, dirs, files in os.walk(input_1):
    dst_dir = src_dir.replace(input_1, output, 1)
    if not os.path.exists(dst_dir):
        os.makedirs(dst_dir)
    for file_ in files:
        src_file = os.path.join(src_dir, file_)
        dst_file = os.path.join(dst_dir, file_)
        if os.path.exists(dst_file):
            os.remove(dst_file)
        shutil.copy(src_file, dst_dir)

for dirpath, dirnames, filenames in os.walk(output):
            for filename in filenames:
                if filename.endswith(('.tif')):
                    doc = psApp.Open(output + "\\" + filename)
                    # Action 'jpg q8' in Photoshop makes some changes like converting to profile srgb :
                    doc = psApp.DoAction('jpg_q8','Default Actions')
                    # here I would like to save my file as jpg quality=8, but I do not know how to do it :    
                    doc.Export ?????
In https://vsfxryan.com/portfolio/python-ph...n-scripts/, there are lines and codes about saving the file as PNG8 (search 'PNG8' in the web page), but how to do it as JPG quality 8?

Thanks Smile
Reply


Messages In This Thread
Python Script to repeat Photoshop action in folders and subfolders - by silfer - Jul-25-2019, 02:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  What script to paste folders thenewcoder 1 687 Nov-29-2023, 09:40 AM
Last Post: Pedroski55
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,384 Jun-29-2023, 11:57 AM
Last Post: gologica
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,392 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Pixel color and action Sartre 4 2,151 Apr-13-2023, 03:26 AM
Last Post: Sartre
Question Running an action only between certain times alexbca 9 1,793 Mar-15-2023, 04:21 PM
Last Post: deanhystad
  Checkbox itens with a button to run action Woogmoog 3 972 Dec-19-2022, 11:54 AM
Last Post: Woogmoog
  python move folders and subfolders not working mg24 5 2,254 Nov-09-2022, 02:24 PM
Last Post: Larz60+
Question Running an action only if time condition is met alexbca 5 1,360 Oct-27-2022, 02:15 PM
Last Post: alexbca
  Repeat request by else stsxbel 2 1,202 Jul-30-2022, 03:34 PM
Last Post: stsxbel
  get out of while loop and stop repeat Frankduc 11 3,075 Apr-26-2022, 10:09 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020