Skip to content

Commit 14ca65f

Browse files
committed
fix for source path
1 parent f3b3480 commit 14ca65f

File tree

4 files changed

+321
-60
lines changed

4 files changed

+321
-60
lines changed

Image Shrinker.alfredworkflow

862 Bytes
Binary file not shown.

src/filecheck.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,48 @@
1616
'heic',
1717
]
1818

19+
image_files = []
20+
for file_path in sys.argv[1:]:
21+
file_extension = Path(file_path).suffix[1:].lower()
22+
if file_extension in WHITELIST_EXT:
23+
img_suffix = os.getenv('img_suffix')
24+
target_folder = os.getenv('target_folder')
25+
path = Path(file_path)
26+
27+
if not (os.getenv('target_folder')) and not (img_suffix):
28+
img_suffix = '_shrinked'
29+
30+
if target_folder:
31+
path = Path(target_folder) / path.name
32+
33+
if img_suffix:
34+
new_file_name = f"{path.stem}{img_suffix}{path.suffix}"
35+
new_file_path = path.with_name(new_file_name)
36+
shutil.copyfile(file_path, new_file_path)
37+
file_path = str(new_file_path)
38+
39+
image_files.append(file_path)
40+
"""
1941
image_files = []
2042
for f in sys.argv[1::]:
2143
ext = Path(f).suffix.replace('.', '').lower()
2244
if ext in WHITELIST_EXT:
45+
img_suffix = os.getenv('img_suffix')
46+
path, filename = os.path.split(f)
47+
if not (os.getenv('target_folder')) and not (img_suffix):
48+
img_suffix = '_shrinked'
49+
if os.getenv('target_folder'):
50+
path = os.getenv('target_folder')
2351
# create a copy if img_suffix is not empty in WF config
24-
if os.getenv('img_suffix'):
25-
path, filename = os.path.split(f)
52+
if img_suffix:
2653
basename, extension = os.path.splitext(filename)
27-
new_file_name = f"{basename}{os.getenv('img_suffix')}{extension}"
54+
new_file_name = f"{basename}{img_suffix}{extension}"
2855
new_file = os.path.join(path, new_file_name)
2956
shutil.copyfile(f, new_file)
3057
f = new_file
3158
3259
image_files.append(f)
60+
"""
3361

3462
files = "\t".join(image_files)
3563

src/get_source_folder.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import os
2+
import sys
3+
4+
source_file = sys.argv[1]
5+
source_path = os.path.dirname(source_file)
6+
sys.stdout.write(source_path)

0 commit comments

Comments
 (0)