Pasting Files From Clipbaord

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Pasting Files From Clipbaord Wed Apr 11, 2018 3:11 am • by typkrft
I am trying to paste theFile into a "Spark," an email application. The first two files that I explicitly name work, but theFile does not. What happens is a strange txt file is pasted that says something to the effect of

Code: Select all
dle2obj formenumindxwanttypepsxfseldalis»» Macintosh HDBDˇˇˇˇLoad_Confirmation_#FFFFFFFF.pdfˇˇˇˇˇˇˇˇ
 cu   DocumentsG/:Users:?????:Documents:Load_Confirmation_20181513_20180213123717.pdf\-Load_Confirmation_20181513_20180213123717.pdf Macintosh HDEUsers/typkrft/Documents/Load_Confirmation_20181513_20180213123717.pdf/ˇˇfromnull


The frustrating thing is that I had this working only a couple weeks ago, but my computer died and I am trying to recreate the script, I can't remember my previous solution. I've replaced potentially sensitive information with ????. Thanks in advance for any assistance.

Code: Select all
set originalClipBoard to the clipboard

tell application "Spark" to activate

tell application "System Events"
   keystroke "n" using {command down}
   delay 0.5
   keystroke "v" using {command down}
   delay 1
   keystroke tab
   keystroke "Please Sign and Return"
   keystroke tab
end tell

delay 0.25

tell application "Finder" to set the clipboard to (POSIX file "/Users/?????/Documents/Work/Setup Paperwork/????.pdf")

tell application "System Events"
   keystroke "v" using {command down}
end tell

delay 0.25

tell application "Finder" to set the clipboard to (POSIX file "/Users/?????/Documents/Work/Setup Paperwork/????.pdf")

tell application "System Events"
   keystroke "v" using {command down}
end tell

delay 0.25

tell application "Finder" to set the clipboard to (POSIX file theFile)


tell application "System Events"
   keystroke "v" using {command down}
end tell

delay 0.25
typkrft
 
Posts: 4
Joined: Wed Apr 11, 2018 3:01 am

Re: Pasting Files From Clipbaord Wed Apr 11, 2018 10:42 am • by Mr_Noodle
Note that theFile is an alias. You'll need to coerce that into the type of data Spark expects in this case. Probably use POSIX path or some variation of that if its the path you want.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Pasting Files From Clipbaord Wed Apr 11, 2018 11:01 am • by typkrft
Mr_Noodle wrote:Note that theFile is an alias. You'll need to coerce that into the type of data Spark expects in this case. Probably use POSIX path or some variation of that if its the path you want.


I had thought that was what I was doing with
Code: Select all
tell application "Finder" to set the clipboard to (POSIX file theFile)
.
But I have also tried
Code: Select all
set thePath to POSIX path of theFile
then
Code: Select all
tell application "Finder" to set the clipboard to (POSIX file thePath)
.
typkrft
 
Posts: 4
Joined: Wed Apr 11, 2018 3:01 am

Re: Pasting Files From Clipbaord Thu Apr 12, 2018 10:50 am • by Mr_Noodle
Are the results any different between those? How about doing:

POSIX file POSIX path of theFile

That would seem to more closely resemble what you did with the hardcoded paths.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Pasting Files From Clipbaord Thu Apr 12, 2018 11:30 am • by typkrft
Mr_Noodle wrote:Are the results any different between those?

Interestingly enough it attaches an attachment, but the size of the attachment is different and predictable. One is smaller, and the text in the attachment is a slightly truncated version of the message I posted originally.

Mr_Noodle wrote:How about doing:

POSIX file POSIX path of theFile

That would seem to more closely resemble what you did with the hardcoded paths.


It throws an error.


I believe this is the relevant error of log.

Code: Select all
2018-04-12 11:13:39.529 HazelHelper[408] DEBUG: Checking events for path /Users/????/Documents, folder Documents
        path = "/Users/????/Documents/Work/Setup Paperwork/BCA.pdf";
) for stream at path: /Users/????/Documents
        path = "/Users/????/Documents/Work/Setup Paperwork/Setup Packet.pdf";
) for stream at path: /Users/????/Documents
    NSLocalizedDescription = "Finder got an error: Can\U2019t get POSIX path.";
    NSLocalizedFailureReason = "Can\U2019t get POSIX path.";
    OSAScriptErrorBriefMessageKey = "Can\U2019t get POSIX path.";
    OSAScriptErrorMessageKey = "Finder got an error: Can\U2019t get POSIX path.";
typkrft
 
Posts: 4
Joined: Wed Apr 11, 2018 3:01 am

Re: Pasting Files From Clipbaord Fri Apr 13, 2018 10:45 am • by Mr_Noodle
I feel like "set thePath to POSIX path of theFile" should work since that resembles the examples I see online. Is that the one that comes up with the attachment? It may be worth looking into why its truncated.

Also, is there a way you can do this without the clipboard? Maybe Spark has AppleScript support?
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Pasting Files From Clipbaord Fri Apr 13, 2018 12:39 pm • by typkrft
Mr_Noodle wrote:I feel like "set thePath to POSIX path of theFile" should work since that resembles the examples I see online. Is that the one that comes up with the attachment? It may be worth looking into why its truncated.

Also, is there a way you can do this without the clipboard? Maybe Spark has AppleScript support?


I desperately wish there was a way, but no Readaddle or whoever makes Spark has completely ignored Applescript in all of their almost perfect programs. I've gotten around it by just pasting the two files having spark open finder to the file and then having applescript CMD+C and CMD+V back in spark, it works just fine, but it's not the most satisfying solution haha. I was able to replicate the same problem in Script Editor, just by naming a variable called theFile to a path then setting the clipboard to it and then trying to paste it in Spark, it is unable to paste anywhere else.
typkrft
 
Posts: 4
Joined: Wed Apr 11, 2018 3:01 am

Re: Pasting Files From Clipbaord Mon Apr 16, 2018 3:58 pm • by Mr_Noodle
Not sure of what's going on here exactly but maybe the Finder solution is the way to go here.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support