Extracting file location to Downloads folder

Copying file from result to Desktop, I run a code to get a result in Applescript, the URL for the location of a file. I want to pull the file onto my Downloads folder.

tell application "Daylite"
set fileURL to eval "

opportunity := selectedObjects firstObject projects objectAtIndex:0.

predicate := NSPredicate predicateWithFormat:‘displayName = “Scan Letter of Authority LOA DSAR”’.
attachments := opportunity fileAttachments.
filteredAttachment := (attachments filteredArrayUsingPredicate:predicate) lastObject.

filteredAttachment retrieveAttachmentWithDelegate:nil error:nil.

localLocation := filteredAttachment cachedURL.

localLocation.

"

end tell

set fileRef to unescapeURL fileURL
set fileRef to change “^file:/+(?:localhost/)?”" into “/” in fileRef with regexp without case sensitive
set fileRef to alias POSIX file fileRef

The result that I get is:

alias “MacintoshFD:Users:alidemirtas:Library:Group Containers:GR26KTJYTV.com.marketcircle.daylite:Library:Caches:FileAttachments:B9B668B7-E687-4D74-B4BD-0B93EBCC863E:6:6B:2017_05_26_14_09_46.pdf”

I’m not sure if I understand correctly, but I’m assuming that you want to copy a file from a given path to the Downloads folder, and that the given path is stored in the fileRef variable as alias (see end of your script).

So, to copy it, this should work:

set destDir to path to downloads folder from user domain

tell application "Finder"
  duplicate fileRef to destDir replacing no exact copy no
end tell

Use replacing yes if you want to overwrite existing files in the Downloads folder without warning.

1 Like

Hi Tom, this is very helpful thank you for this.

Is it possible to do the following separately?
encrypt the file/document with a particular password then attach it to Mail as a new message (pushing the url of the file into the Mail as an attachment ready to send the email?)

Many thanks for your help

Since this has nothing to do with this topic I think it wouldn’t be a bad idea to open a new topic. (And please specify which program you are using to encrypt the document.)

Have you already searched the forum for “attachment mail” or so? You will probably find useful things like this:


If you consider my post above a solution to your question, then feel free to check the “Solved” checkbox at the bottom of that post.

1 Like

I know how to attach files in KM Mail, I now need to learn how to encrypt the file using a password. Thank you.

First and foremost to encrypt documents you need some encryption program. For an asymmetric encryption you likely could use some PGP plugin for Mail, for example from GPG Tools. I think the attachment will be encrypted automatically by the plugin.

For a symmetric encryption you could create an encrypted .dmg (if the recipient is working on a Mac), or, for cross-platform, use the encryption option of 7z [1], or some other possibilities.

Once you know how you are going to encrypt the document, we can build a macro around it.


[1] 7z is available for macOS as p7zip, a very useful program. (Easily installable via Homebrew.)

Hi demirtas,

me, too, happy to see you again :slightly_smiling_face:

But give me a little help: the post you are pointing to is two over years old, and ATM I don’t see any relation to the code in your screenshot.

Give me a hint please or/and some link to a post of mine that points me in the right direction…

Furthermore, your screenshot seems weird: I see a regex with an opening typographic quote, then a straight quote…

It seems my reply crossed with your deletion of your post.

Post it again, with some more info (see my previous post). If you want.

1 Like

I have managed to resolve it, thank you so much. I did not want to be a burden on your precious time. I am much obliged for your help. Took me a few hours but it's finally resolved.

What? I didn’t do anything to help you. (?)

Have I upset you in any way? You are not a burden, I just asked for more info, since the post you pointed to is 2 years old, and didn’t seem to be related to the screenshot you had posted.

Sorry again, if I upset you.

1 Like

Absolute not, you have helped me previously. Simply look up in this thread.

How would I be able to do this for each Item in collection in SingleLine in a single AppleScript as per the image. I would like the applescript to do the for each line if possible?

basically for each line execute this applescript code, it seems to be buggy moving back and forth from KM.

Oh, I have no clue of the Daylight app (though I remotly remember some discussion about it, some years ago). The best I can do, is checking your AppleScript for general errors (that are not related to Daylight’s dictionary).

For that you have to upload the complete AppleScript.


PS:

Post it as fenced code, or zip and upload it as file.
Or just upload the macro containing the script.

it seems to me when he applescript is triggering and saving a file KM moves onto the next action without allowing the applescript to fully finish. If there was a possibility to tell KM to wait until the AppleScript fully completes that would be great.

What does the code do? I have selected some stuff and based upon my selection it goes in looking for a file with a matching name and downloads that to the Downloads folder.

22) PIRs - Download LOAs from selected 'Forms' into Downloads folder for electronic submission.kmmacros (43.0 KB)

I think, this can indeed happen, and it could be relevant if the saving process takes some time. KM, as far as I know, only waites for the AppleScript to complete.

You have tried it with pauses, right?

Yes I have tried it with pauses and I cannot seem to get them right. If the pause is not long enough when it tries to execute the applescript again it gives an error.

When the pause is long enough, it works?

I cannot seem to find the pause long enough for it to work. It seems to me that the execution of the AppleScript is buggy, because KM moves on without allowing it to save. Is there a code I can place inApplescript where applescript will pause itself until it has fully completed executing the script?

Trying to understand:

Do you mean you experimented with various pause lengths (from very short up to very long), and nothing succeeded?

Yes that's the problem I am having. As per the applescript in the macro, is it possible to pause until the copying has completed?

Pause until this has completed;
tell application "Finder"
duplicate fileRef to destDir replacing yes exact copy yes
end tell