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