Jump to content

Action on file to create subfolder and move it to a specific folder


Recommended Posts

Posted

Hello dear Alfred forum members

 

I am new to Alfred and am already enjoying using it.

 

There is one workflow that I would like to create and it seems fully out of my capabilities.

 

Basically I would like to file an email attachment into a folder that is names with date and then the attachment file name and move it to a specific folder.

 

Is this something that can be done with Alfred?

 

All I have so far is a Universal Action called "FilingCustom" but then I already stop because I can't see how to create a folder.

 

I guess it needs scripting from here? Or could Alfred do that with its own tools and someone could guide me into the right direction?

 

That would be very much appreciated 🙂

 

Greetings, Chris

Posted (edited)

Hi @Alfred-Chris, welcome to the forum.

 

It sounds like it's probably possible, but you're going to have to provide a significantly more precise description of what you're trying to achieve if you want actionable advice.

 

4 hours ago, Alfred-Chris said:

Basically I would like to file an email attachment into a folder that is names with date and then the attachment file name and move it to a specific folder.

 

I mean, what are we talking about here? Is the folder named with the date the same folder as the "specific folder"?

 

This is too vague to give you anything useable.

Edited by deanishe
Posted

Hi deanishe

 

Thanks a lot for answering and I ca see that you are absolutely right.

Let me try and explain better.

 

The workflow would be:

 

- Email with attachment arrived

    - The attachment's filename is "Project1-100-001-B - Document name.pdf"

- I highlight the attachment inside the email and trigger the Alfred Action Menu

- In here I would like to have an action that will do the following:

    - Create a folder that has the format "Date added - Attachment's Filename" in a specific folder (e.g. inside "Documents")

        - (example here: The folder would be called: "2021-08-28 - Project1-100-001-B - Document name"

    - The attachment will be copied into that folder

    - Ideally: The folder will be tagged "yellow"

 

That's it.

I hope it makes a more sense now.

 

And thanks again for any help in advance already 🙂

 

Chris

Posted (edited)

That's a really good description. Thanks. One immediate issue, though:

 

6 minutes ago, Alfred-Chris said:

I highlight the attachment inside the email and trigger the Alfred Action Menu

 

In which email program? None of the email clients I use allow you to action attached files in Alfred.

Edited by deanishe
Posted (edited)

I use Spark from Readdle and it works in there.

 

I attached a short screenshot where you can see how Alfred addresses the file inside the filesystem of the mailbox, in case you are interested.

 

I can't say that I can recommend Spark though, for the reason that the company finances itself trading with your data.

Screen Shot 2021-08-28 at 13.28.41.png

Edited by Alfred-Chris
Posted
Just now, Alfred-Chris said:

I can't say that I can recommend Spark though, for the reason that the company finances itself using trading with your data.

 

Yeah. I wouldn't touch Spark with a bargepole for precisely this reason. I don't know if they still do, but they also used to misrepresent Spark as a privacy-respecting email client.

 

This workflow should do what you want. It's called "Save Attachments", but it will work with any files.

 

It defaults to saving files to ~/Documents, but you can change that in the workflow's settings sheet.

Posted

Wow, this is amazing!

I did not expect such great help, so many many thanks for the workflow and I hope it will also help someone else one other day!

 

I will need to understand coding, that's for sure.

And it will be very helpful that I can experiment with the workflow you sent me now and can try and understand this a bit better.

 

Kind Regards,

Chris

Posted (edited)
2 hours ago, Alfred-Chris said:

 

I just saw that -  I bought you a beer 🙂

 

Cheers!

 

Thanks very much! It took me a bit to figure out why "YNA" had sent me money. I'll invest it in a Herrengedeck ;)

Edited by deanishe
Posted

Hi @deanishe

 

This all works very well. Thanks again.

 

May I ask one follow up question on this topic.

Currently when the email has several PDF files all get files in their own dedicated folder. As epxected!

 

Would it also be possible to combine those PDF's in one folder?

 

Probably to keep it simple the name could just be the "added-date" and then the name of the first PDF file, if that makes sense.

 

Or is this tough to program?

 

  • 6 months later...
Posted

This script always worked perfect.

But (it seems) since the latest MacOS update I get the error message

 

Reason: Couldn't posix_spawn: error 2
The external script may not exist, or doesn't have execute (+x) permissions.

 

I saw @deanishe explanation on the link below, but I am not siure how to fix this.

I tried to remove and then add Alfred from "Accessibility" inside the privacy settings menu.

But it didn;t help to solve the issue.

 

Does it require to rewrite the script for Alfred?

 

 

Posted
6 hours ago, Alfred-Chris said:

But (it seems) since the latest MacOS update I get the error message

 

If you’re on Monterey 12.3, you’ll need further fixes.

  1. Reinstall Python 2.
  2. Redownload and reinstall the Workflow, to regain the executable bit.
  3. Open the Workflow in the Finder.
  4. Locate the save_attachments.py file and open it in a text editor.
  5. Change the top line from #!/usr/bin/python to (if you are on an Intel Mac) #!/usr/local/bin/python or (if you are on Apple Silicon) #!/opt/homebrew/bin/python.
  • 1 month later...
Posted

Hi, sorry to ask again.

 

Is it possible somehow for me to convert the workflow that Deanishe once created from Python 2 to Python 3?

 

Is there maybe a manual for that?

 

I would like to try it instead if frickeling with MacOS (now and in the future).

 

Thanks for any tip 🙂

Posted

Hi Giovanni - thanks a lot for converting the workflow.

 

At the moment I can't get it to work unfortunately.

It doesn;t even show up in the drop down menu when I use the shortcut on the file.

 

But I will try again when I have more time.

 

Thanks again and more later,

 

Chris

Posted

I get this error message in the log.

 

I will try and look at the .py file myself a bit later.

 

Quote

[12:15:40.927] Logging Started...
[12:16:07.857] Save Attachment[Universal Action] Processing complete
[12:16:07.860] Save Attachment[Universal Action] Passing output '/Users/ck/Library/Group Containers/3L68KQB4HG.group.com.readdle.smartemail/databases/messagesData/9/280400/example.pdf' to Run Script
[12:16:07.997] ERROR: Save Attachment[Run Script] Traceback (most recent call last):
  File "/Users/ck/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.4F8296F6-812D-4017-B9FE-08B804951DE9/save_attachment.py", line 16, in <module>
    from Cocoa import NSURL
ModuleNotFoundError: No module named 'Cocoa'

 

Posted

Ok,

 

I guess this means that it doesn't find the right Python (python3) installation.

 

If someone knows what to do to make it work, that would be cool, elsewise I will need to google my way through it.

 

Talk later 🙂

Posted
1 hour ago, Alfred-Chris said:

I guess this means that it doesn't find the right Python (python3) installation.


No, it means it’s missing a package. One which used to ship with macOS but no longer does, to make a bridge between Python and the macOS APIs.

 

Running python3 -m pip install PyObjC in the Terminal may fix it.

Posted
19 hours ago, vitor said:

Running python3 -m pip install PyObjC in the Terminal may fix it.

 

Unfortunately that didn't fix it yet.

I got the same error message.

 

I am not sure how to address this issue.

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...