Jump to content

RenameAction — Renames a directory or file (preserving the extension)


Recommended Posts

  • 2 weeks later...
  • 3 months later...
1 hour ago, pontus said:

Great workflow, very useful, thanks!

 

Thank you. Glad you find it useful.

 

1 hour ago, pontus said:

I want to trigger it externally (as described here) but then the external trigger must be placed before the parsing script. 

 

To trigger it externally, you’ll need to add an External Trigger that connects to the top Run Script.

 

1 hour ago, pontus said:

Any specific reason for the placement of the trigger? 

 

Yes. Admittedly that External Trigger is more like an Internal Trigger. It’s not meant to ever be called from outside the Workflow. I’m using it as a trick to pass a bunch of variables around without having to resort to temporary files.

Link to comment
56 minutes ago, pontus said:

(Shouldn't every workflow have an external trigger hehe).

 

Issue is some Workflows have so many possible inputs, adding an External Trigger for all can become quite a mess. So I typically only add the ones I need or that I think will be particularly useful. If someone else needs another, its easy enough to add and I can even help the user make it custom.

 

1 hour ago, pontus said:

For me it works fine without the "trick", is it for older versions of alfred?

 

You’d need to show me your version working without for me to say for sure if I could use your approach.

Link to comment
  • 2 weeks later...
  • 1 month later...

This is a very helpful workflow - it functions well and I also edited it to post a notification that says "Renamed from {var:oldfilename} to {var:newfilename}".

However I did notice that if you rename file A the name of an existing file B of the same type in the same directory it overwrites file B (and I have no idea where the old one goes - not in the trash :). Hopefully and presumably something the filesystem can manage). Similarly renaming folder A to the name of folder B in the same directory will move folder A into folder B.

 

Ideally both of these scenarios would report an error and not follow through with the operation, or utilize similar behavior as Finder, by addending "1" "2" "3" etc. to the new file name (or if that's not possible perhaps addending "copy from {time}" to the filename using the {time} dynamic placeholder as a unique identifier)

 

Let me if I'm missing something, but for now I won't use this since I may accidentally delete files with it.

 

Thanks!

Link to comment
8 hours ago, deanishe said:

Yeah, that sounds like the default behaviour of the mv command.

 

It is.

 

10 hours ago, pacifist said:

similar behavior as Finder, by addending "1" "2" "3" etc. to the new file name

 

That’s for copying files. Finder doesn’t have such a scheme for renaming — it aborts and tells you to pick a different name.

 

10 hours ago, pacifist said:

(or if that's not possible perhaps addending "copy from {time}" to the filename using the {time} dynamic placeholder as a unique identifier)

 

Made it into something like that. If the path already exists, it’ll append the date and time to the name (and in the extremely unlikely event a file name with that exact same date string already existed, it’ll try again until it’s sure the name is unique.

Link to comment

Update.


Prevent overwriting files.

 

Also updated to the latest version of OneUpdater (including lowering the update check frequency to 4 days).


To update, download the latest version (same URL) or wait a few days and it’ll prompt you to on next usage, since it uses OneUpdater.

Link to comment
  • 7 months later...
  • 1 year later...

This is great, thank you so much!

 

One question, I am trying to augment this to duplicate a file first before renaming it. I am able to duplicate the file, but I can't figure out how to rename the duplicated file, it always renames the original file? Is there a simple one to do duplicate the file first and rename the duplicate?

 

thanks so much!

--------------------

Update: I was able to find a work around by creating a hotkey for this workflow, and then creating a separate workflow that executes a key combo to duplicate a file, then another key combo for this workflows hotkey. Whew. Bit of a round about, but it works! I was also able to make a tiny edit to the bash script to remove the 'copy' in the duplicated file name as well. Thanks again for the great workflow!

Edited by proxemics
Link to comment
  • 1 month later...
  • 5 months later...
4 hours ago, heyJoeCampbell said:

how can I get the workflow work recursively?

 

Either I don’t understand what you want (please elaborate), or the answer to your question is probably in the README (please see the top post).

Link to comment
On 5/18/2021 at 7:43 PM, vitor said:

 

Either I don’t understand what you want (please elaborate), or the answer to your question is probably in the README (please see the top post).

 

My apologies - I thought the workflow had the ability to perform Find & Replace when renaming folders and files.

 

But is does warrant the consideration for the developing such a workflow:

 

  1. Select Folder via file action
  2. Enter search string
  3. Enter replace string

The workflow then replaces all instances of the string recursively.

 

Does it sound like a worthy workflow?

Link to comment
On 5/20/2021 at 7:41 AM, heyJoeCampbell said:

Does it sound like a worthy workflow?

 

I have built Workflows that literally no one else in the world could or would want to use. I’ve also built Workflows on request which I’m pretty sure only one person in the world uses. Whatever you find worthy to build as a Workflow is up to you.

 

Or are you asking if I would build this one, like I’ve built others for you in the past? Because if so, please just say that. I appreciate straightforwardness and find it hard to communicate when I feel the subject is being tip-toed around.

 

Either way, I’ll pass on this one. I’ve been prioritising adding major improvements to my main Workflows this week and I’m predicting that what you’re asking for will be more effort than it’s worth. As someone who has built several tools to handle renaming, it takes too much testing and checking for edge cases, seeing as it’s potentially destructive.

Link to comment
  • 2 weeks later...
Posted (edited)

@heyJoeCampbell I had an idea and made a Workflow to satisfy what you asked for [link removed after download]. Instead of building and testing all the logic, I remembered I could use another tool for this. This received limited testing, so you use it at your own risk! I don’t think anything bad is going to happen, but who knows if you use some weird shell characters that get expanded to something they shouldn’t or the like.


It’s a File Action which only works on directories, and one at a time. Select the directory, press the shortcut, then give the “from” and “to” strings you want to modify. All file and children directories will be renamed with that substitution.

Edited by vitor
Link to comment

See, I told you about the limited testing! An issue of that tool (which may be addressed on a future update, they say) is that it acts on the whole path, so it may rename a directory and then can’t get to the files inside (because the parent’s name changed). So you can avoid that by not having the parent directory be named with what you want to replace.


These are the types of issues I was talking about that require a bunch of testing. So as I expect you understand, I won’t keep iterating on it. If they update the tool (you may ask, I suppose) and you let me know, I may update the Workflow accordingly.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...