r/applescript • u/Roccobot • Mar 15 '23
I failed at implementing a Finder task with AppleScript
Hello everybody,
what I'm trying to do is pretty straightforward as a concept, but it is probably much more complicated in its implementation. The task is
- If nothing is selected in Finder, or just one file/folder is selected, display 'Select at least two elements'.
- Check if the 2+ elements are all of the same kind. If not, display 'The selection must contain only files or only folders'.
- Check if the selected elements have a name with a common substring (starting from the first character). If they don't, display 'Selected elements have no common prefix'. The common prefix should be at least 6 characters long and should be interrupted by the first space.
- For every group of files|folders with the same prefix in the selection, create a subfolder with the prefix itself as a name, then move the matching group inside it.
- Clean the new folder names deleting ` - ` sequences at the end of the name, and trimming initial or trailing spaces.
- Display '<X> files moved, <Y> files share no prefix with other elements in the selection' as a task sumary.
Hope someone can help me with this, thanks!
1
Upvotes
1
u/chrismo80 Mar 15 '23
What does your code look like?
1
u/copperdomebodha Mar 15 '23
It doesn't look like you failed. Did you fail, or did you not try? Posting code ( even very bad code ) goes a long way to convincing others that you're not just trying to use them as if they were an AI.
I had some code for a similar action, so here's steps 1 thru 4 of your task. If you take a stab at coding your naming restrictions and action summary and post your code here I would be happy to help you solve any problems you encounter .