Applescript to upload open file to web page
I want an easier way to get files into my intranet. I open a file, like a PDF or Word file. When I figure out what it is (say someone has emailed it to me), I want to click something that causes the following actions:
1) My web browser opens and goes to my intranet Add File page
2) In the form, there is a file upload box
3) The file is in that box so I don`t need to navigate to it.
Per the comment below, here is what the HTML form looks like (although I am not aware of a a different way to do it):
<form method="post" action="process.p开发者_如何学Chp" enctype="multipart/form-data">
File to upload: <input type="file">
<input type="submit" value="submit">
</form>
Just in case you care, here are more details: Using Mac OSX (hence, Applescript), browser is Safari.
Can someone help me?
You have few things your gonna need to sort out.
First: you need to figure where you want to trigger this code from. You could write a script and put it in the script menu for easy access. But that does solve how your going to find out where the file lives because your gonna need that to put it into the form. if your always going to do it from mail then you only have to target mail but if you want to do it from word and acrobat and however many apps then you have allot more code to right.
2 Safari isn't all that scriptable but you certainly can open a url see this thread to see how but then you will need to run javascript in the applescript to set the value of file form to the location of the file
To Answer Some Questions
all thee apps in question use different commands to get the file path and when it comes to mail app it's more complicated because you have to look at the attachments of the message and figure out which one you want and then get its path. AND then preview isn't' scriptable and powerpoint I'm not sure will give you the file path.
here are two examples of file path
tell application "Microsoft Word" to set thepath to get path of document 1
tell application "Adobe Acrobat Pro" to set thepath to file alias of document 1
set thepath to posix path of thepath -- this will make it /path/to/file
so once you have "thepath" then you run JavaScript to set the value of the file input to "thepath"
hope that all makes sense
Here's another answer, which I hadn't thought possible:
You can drag and drop an attachment from an email onto the "CHOOSE FORM" form field in a form for a web page. It works. Put your email window on the left of the screen. Put your web page on the right. Then drag and drop. This is very helpful.
I'm not entirely sure what your question technically is. If you are trying to script via Safari injecting the file name into the form then it can't be done. That's a security feature HTML has to ensure files aren't unscrupulously sent from your computer. (It would be nice as there are many forms I'd love to script in this fashion)
If you are just trying to quickly get files to your form then the answer of thf is best. Just keep a small window open and manually drop them there. If you want to automate this though there's just no solution.
精彩评论