-
Notifications
You must be signed in to change notification settings - Fork 0
/
ss-rename
executable file
·132 lines (122 loc) · 3.17 KB
/
ss-rename
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/perl -ws
# renames screenshots on the desktop to 2020-02-02.1234.55.ext
#
# my $dir = "$ENV{HOME}/Desktop";
no warnings 'once';
my @dirs = ("$ENV{HOME}/Desktop", "$ENV{HOME}/Pictures");
my $dryrun=0;
if($n) {
$dryrun=1;
print("Dry run - no actions will actually be taken\n");
}
sub d(@) {
return unless $v;
print @_;
print "\n";
}
sub dd(@) {
return unless $v;
print @_;
}
if(scalar @ARGV > 0) {
$dir = $ARGV[0];
shift;
@dirs=($dir)
}
sub mv($$) {
my $src = shift;
my $dst = shift;
if($dryrun) {
print("mv \"$src\" \"$dst\"\n");
} else {
rename $src, $dst || print("ss-rename: renaming \"$src\" to \"$dst\" failed: $!\n");
print("ss-rename: $dst\n");
}
}
sub ssrename($) {
my $dir = shift;
chdir($dir);
dd("PWD is ", `pwd`);
# Screen Recording 2020-11-19 at 18.13.50.mov
# Screenshot 2022-07-04 at 5.33.06 PM
for my $ss (<"*">) {
my $newname="";
d("ss-rename: checking \"$ss\"");
if($ss =~ /S.* ?(recording|shot).* (\d\d\d\d-\d\d-\d\d) at (\d+)\.(\d\d\.\d\d)( [AP]M)?\.(\w\w\w)/i) {
my $date = $2;
my $hour = $3;
my $minutes = $4;
d("ss-rename: renaming \"$ss\"");
my $time=$3;
my $ext = $6;
if(defined $5 && $5 eq " PM" && $hour < 12) {
dd("ss-rename: adding 12 hours to $hour,");
$hour += 12;
d(" \"$hour\"");
} elsif(defined $5 && $5 eq " AM" && $hour == 12) {
dd("ss-rename: using 00 for midnight, ");
$hour -= 12;
d(" \"$hour\"");
}
$hour = "0${hour}" if $hour < 10;
$newname="${date}.${hour}${minutes}.${ext}";
if(-e $newname) {
warn "$0: \"$newname\" already exists. skipping $ss\n";
next;
}
d("ss-rename: renaming to \"$newname\"");
mv $ss, $newname;
}
elsif($ss =~ /S.* ?(recording|shot).* (\d\d\d\d\-\d\d-\d\d) at (\d+)\.(\d\d\.\d\d) (am|pm|AM|PM)(.*)\.([a-z]+)$/i) {
d("Found Screen $1");
my $date = $2;
my $hour = $3;
my $minsec = $4;
my $extra = $6;
my $ext = $7;
my $ampm = lc $5;
$hour += 12 if $ampm eq "pm";
$newname="${date}.${hour}${minsec}${extra}.${ext}";
}
elsif($ss =~ /vlcsnap-(\d\d\d\d-\d\d-\d\d)-(\d\d)h(\d\d)m(\d\d)s(\d\d\d)\.([a-z]+)$/i) {
d("Found vlcsnap-$1");
my $date = $1;
my $hour = $2;
my $min = $3;
my $sec = $4;
my $ms = $5;
my $ext = $6;
$newname="${date}.${hour}${min}.${sec}.${ms}.$ext";
}
elsif($ss =~ /^RPReplay_Final(\d+)\.(\w+)$/) {
my $timestamp = `date -r $1 +%F.%H%M`;
chomp($timestamp);
my $ext = lc $2;
$newname = "$timestamp.$ext";
}
else {
next;
}
if(-e $newname) {
d("$0: \"$newname\" already exists. skipping $ss");
next;
}
d("ss-rename: \"$ss\" => \"$newname\"");
mv $ss, $newname;
}
# Simulator Screen Shot - iPhone Xs Max (UAT, FR) - 2018-12-04 at 15.26.31
for my $ss (<"Simulator Screen ?Shot*">, <"Simulator Screen Recording*">) {
print "$ss\n";
if($ss =~ /Simulator Screen ?\w* - (.*) - (\d\d\d\d\-\d\d-\d\d) at (\d\d)\.(\d\d\.\d\d)\.([a-z][a-z][a-z])/) {
my $newname="simulator.${2}.${3}${4}.${1}.${5}";
if(-e $newname) {
warn "$0: \"$newname\" already exists. skipping $ss\n";
next;
}
mv $ss, $newname;
}
}
}
foreach $dir (@dirs) {
ssrename $dir;
}