Send email with attachment does not work

Hi, I have used an Applescript to get the location of a file as a result. I want to send an email using KM with the file attached. When I place the result into Safari i can see the file with a slight variation in its URL. But when I place the result into KM action Mail (create new mail message and leave open) Attach part KM does not obtain the file. I have also tried to place the Safari’s version of the amended URL and KM still does not obtain the file

Here are the results of the URL for the file.

Applescript result:

file://localhost/Users/alidemirtas/Library/Caches/com.marketcircle.Daylite4/FileAttachments/B9B668B7-E687-4D74-B4BD-0B93EBCC863E/E/EC/Screen%20Shot%202015-06-21%20at%2000.48.44.png

Safari version of the URL:

file:///Users/alidemirtas/Library/Caches/com.marketcircle.Daylite4/FileAttachments/B9B668B7-E687-4D74-B4BD-0B93EBCC863E/E/EC/Screen%20Shot%202015-06-21%20at%2000.48.44.png

Please could you assist?

Hey Ali,

Neither one of those URLs is appropriate for what you’re trying to do.

What script are you using to get this result?

-Chris

Hi CCStone,

Thank you for your response.

I will send you a personal message including the script, if that’s ok?

Thank you

Ali

Hey Ali,

No worries.

I don’t know if DayLite will let you get an alias or posix path instead of a cachedURL, but that’s where your problem lies.

You have to turn that URL form into a valid file reference.

There are several ways to do that, but it is probably simplest in this case to amend your AppleScript.

-Chris


set fileURL to "file://localhost/Users/alidemirtas/Library/Caches/com.marketcircle.Daylite4/FileAttachments/B9B668B7-E687-4D74-B4BD-0B93EBCC863E/E/EC/Screen%20Shot%202015-06-21%20at%2000.48.44.png"
set filePosixPath to findReplTIDS("file://localhost", "", fileURL)
set fileAlias to alias POSIX file filePosixPath

------------------------------------------------------------
--» findReplTIDS()
------------------------------------------------------------
--  Task:  Find/Replace using applescript's text item delimiters.
--  dMod: 2011/09/12 16:21
------------------------------------------------------------
on findReplTIDS(_find, _replace, _string)
  set oldTIDS to AppleScript's text item delimiters
  set AppleScript's text item delimiters to _find
  set _string to text items of _string
  set AppleScript's text item delimiters to _replace
  set _string to _string as text
end findReplTIDS
------------------------------------------------------------

Or (less generically) :wink:

set fileURL to "file://localhost/Users/alidemirtas/Library/Caches/com.marketcircle.Daylite4/FileAttachments/B9B668B7-E687-4D74-B4BD-0B93EBCC863E/E/EC/Screen%20Shot%202015-06-21%20at%2000.48.44.png"
set filePosixPath to text 17 thru -1 of fileURL
set fileAlias to alias POSIX file filePosixPath

– Alain

1 Like

Thank you both for your responses, I have attempted both and in each i get the following error message

Script Error:

Can’t get alias (file “MacintoshFD:Users:alidemirtas:Library:Caches:com.marketcircle.Daylite4:FileAttachments:B9B668B7-E687-4D74-B4BD-0B93EBCC863E:E:EC:Screen%20Shot%202015-06-21%20at%2000.48.44.png”).

Is there a way to overcome this?

Or more specifically.  :smiley:

I nearly always prefer to use regular expressions for text matching and munging.

------------------------------------------------------------
# REQUIRES the Satimage.osax.
# http://tinyurl.com/dc3soh
------------------------------------------------------------
set fileURL01 to "file://localhost/Users/alidemirtas/Library/Caches/com.marketcircle.Daylite4/FileAttachments/B9B668B7-E687-4D74-B4BD-0B93EBCC863E/E/EC/Screen%20Shot%202015-06-21%20at%2000.48.44.png"
set fileURL02 to "file:///Users/username/Documents/Documentation/Regular%20Expressions/Jan%20Goyvaerts%20%E2%86%92%20www.regular-expressions.info/Regular%20Expressions%20The%20Complete%20Tutorial.pdf"

set file01Path to change "^file:/+(?:localhost/)?" into "/" in fileURL01 with regexp without case sensitive
set file02Path to change "^file:/+(?:localhost/)?" into "/" in fileURL02 with regexp without case sensitive

Note that the same regular expression is used for both.

* This regular expression should work fine with Keyboard Maestro’s built-in regex.

-Chris

1 Like

Hi CC Stone, thank you for this. I dont receive an error message now but the result of the URL does not load up any image or pdf :). I have tried this in KM and Safari too nothing is loading up with the result.

“/Users/username/Documents/Documentation/Regular%20Expressions/Jan%20Goyvaerts%20%E2%86%92%20www.regular-expressions.info/Regular%20Expressions%20The%20Complete%20Tutorial.pdf

Hey Ali,

Heck. I thought I’d tested that more thoroughly.

The file-URL has to be unescaped.

This script uses the Satimage.osax for both regex and to unescape the file-URL.

------------------------------------------------------------
# REQUIRES the Satimage.osax
# http://tinyurl.com/dc3soh
------------------------------------------------------------
set fileURL to "file:///Users/username/Documents/Documentation/Regular%20Expressions/Jan%20Goyvaerts%20%E2%86%92%20www.regular-expressions.info/Regular%20Expressions%20The%20Complete%20Tutorial.pdf"
set filePath to change "^file:/+(?:localhost/)?" into "/" in fileURL with regexp without case sensitive

--> "/Users/username/Documents/Documentation/Regular%20Expressions/Jan%20Goyvaerts%20%E2%86%92%20www.regular-expressions.info/Regular%20Expressions%20The%20Complete%20Tutorial.pdf"

set filePath to unescapeURL filePath

--> "/Users/username/Documents/Documentation/Regular Expressions/Jan Goyvaerts → www.regular-expressions.info/Regular Expressions The Complete Tutorial.pdf"

set fileAlias to alias POSIX file filePath

--> alias "Mercury:Users:username:Documents:Documentation:Regular Expressions:Jan Goyvaerts → www.regular-expressions.info:Regular Expressions The Complete Tutorial.pdf"
------------------------------------------------------------

Keyboard Maestro has its own search/replace with regex, and it has a filter for unescaping a URL – so this job can be done without the Satimage.osax.

-Chris