forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodify-extension.sh
executable file
·51 lines (44 loc) · 1.3 KB
/
modify-extension.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Modify File Extension
# @raycast.mode compact
# Optional parameters:
# @raycast.icon 🌵
# @raycast.argument1 { "type": "text", "placeholder": "Before" }
# @raycast.argument2 { "type": "text", "placeholder": "After" }
# @Documentation:
# @raycast.description Batch modify the file in the current directory or the specified extension of the selected file
# @raycast.author LokHsu
# @raycast.authorURL https://github.com/lokhsu
finder=$(
osascript <<EOF
tell application "Finder"
try
set finderPath to (POSIX path of (the selection as alias))
on error
set finderPath to (POSIX path of (folder of the front window as alias))
end try
end tell
return finderPath
EOF
)
count=0
if [ -d $finder ]; then
for file in `ls ${finder}`
do
if [[ $file =~ \.$1$ ]]; then
count=$[$count+1]
convert=${finder}${file}
mv "${convert}" "${convert%.$1}.$2";
fi
done
elif [[ $finder =~ \.$1$ ]]; then
mv "${finder}" "${finder%.$1}.$2";
count=$[$count+1]
fi
if [ $count -gt 0 ]; then
echo "$count files modified successfully"
else
echo "no files to convert"
fi