I just want to change my automator quick action from my current script of YYYYMMDD to YYMMDD. Seems like it should be simple enough but I've been trying to figure this out for days now && I'm overwhelmed.
Hi, this is what I have:
for f in "$@"
do
filedate=$(date -r $(stat -f %B $f) +%Y%m%d);
filename=$f:t
filepath=$f:h
mv $filepath/{"$filename","$filedate $filename"}
done
I have searched everywhere on how to adjust this && I can't seem to figure it out. I know, I know that YYYYMMDD is preferred but I want it in the YYMMDD format.
Also, I tried doing this:
for f in "$@"
do
filedate=$(date -r $(stat -f %B $f) +%Y%m%d_);
filename=$f:t
filepath=$f:h
mv $filepath/{"$filename","$filedate $filename"}
done
At the end of the date I put an underscore as I want all my dates to follow with that. But when I run it, it comes back with a space after. So YYYYMMDD_ blahblah.png for examples. How do I get rid of this space since it's not even in the script? Also, recommendations on where I can learn more about automator && scripting would be great. I know there's a ton of stuff out there but if there are any particular recommendations that would awesome. Thanks.
In the format string used with the
datecommand,%Yexpands to the 4-digit year (currently "2024"), and%yexpands to a 2-digit year (currently "24"). Just change%Yto%y.(I'll take your word for it that you have a good reason to do this.)
As for the space, it's in your
mvcommand:You want, I presume, to concatenate
$filedate(which has a trailing underscore) and$filenamewith no space.Or you could set
$filedateto a value without the underscore, and add the underscore in themvcommand:I personally think that's cleaner. Note that you need to add curly braces because
_could be part of an identifier.