Applescript Webforms - ajax

I am trying to make an applescript that submit a form on mxtoolbox.com that uses AJAX at this link:
http://mxtoolbox.com/EmailHeaders.aspx
tell application "Safari"
activate
tell (make new document) to set URL to "http://mxtoolbox.com/EmailHeaders.aspx"
delay 10
tell application "System Events"
-- Copies text from variable headerText to clipboard and paste. Faster than keystroke headerText
set the clipboard to headerText
keystroke "v" using command down
end tell
end tell
Any ideas?
A suggestion was the following but it still did not work:
tell application "Safari"
activate
tell (make new document) to set URL to "http://mxtoolbox.com/EmailHeaders.aspx"
delay 10
tell application "System Events"
set the clipboard to headerText
keystroke "v" using command down
tell application "Safari"
do JavaScript ("
document.getElementById('ctl00_ContentPlaceHolder1_txtToolInput').value='" & headerText as text) & "';
document.getElementById('ctl00_ContentPlaceHolder1_btnAction').click();
" in document 1
end tell
end tell
end tell

You could do this with JavaScript:
set headerText to "test"
tell application "Safari"
activate
tell (make new document) to set URL to "http://mxtoolbox.com/EmailHeaders.aspx"
delay 5
do JavaScript "
document.getElementById('ctl00_ContentPlaceHolder1_txtToolInput').value=" & quoted form of headerText & ";
document.getElementById('ctl00_ContentPlaceHolder1_btnAction').click()" in document 1
end tell

Related

Applescript keystroke fails

I have a problem with my application, I want AppleScript to type "date" in Terminal:
(
activate application "Terminal"
tell application "System Events"
keystroke "date"
keystroke return
end tell
)
It works, but if the language of my keyboard is set to Russian, my app types "####" instead of "date". How to make AppleScript always use the English keyboard mapping?
If you have to send a string to the cursor/insertion point, you can avoid the keystroke command by storing the string on the clipboard and then pasting it.
tell application "Terminal" to activate
set theString to "date"
set the clipboard to theString
delay 0.1
tell application "System Events"
tell process "Terminal"
tell menu bar item "Edit" of menu bar 1
click menu item "Paste" of menu 1
end tell
end tell
end tell
delay 0.1
You should also explore sending a command to the terminal window as a command. Tell a Terminal window to do script.
tell application "Terminal"
activate
set thisWindow to do script "echo 'hello world'" in window 1
do script "echo 'goodbye all'" in thisWindow
end tell
You didn't give enough details of what you're doing to know how best to solve your problem.

How to find the Full path to a most recent added file using AppleScript?

I'm using Automator appleScript to upload new pictures to my Instagram.
The script trigger when new file is added to a folder updates
on adding folder items to myFolder after receiving FileList
repeat with aFile in FileList
activate application "Uploader HD for Instagram"
delay 0.5
delay 0.5
tell application "System Events"
tell process "Uploader HD for Instagram"
click menu item "Open..." of menu 1 of menu bar item "File" of menu bar 1
end tell
end tell
delay 1
tell application "System Events"
keystroke "G" using {command down, shift down}
delay 0.5
keystroke myFolder
delay 1
delay 1
keystroke return
keystroke (ASCII character 31)
delay 1
keystroke return
delay 1
keystroke tab
end tell
tell application "System Events"
tell process "Uploader HD for Instagram"
click button "Post" of window "Uploader HD for Instagram"
delay 1
tell application "Uploader HD for Instagram"
quit
end tell
end tell
end tell
try
tell application "Finder"
delete (every item of folder myFolder whose name ends with ".jpg")
end tell
on error
display dialog ("Error. Couldn't Move the File") buttons {"OK"}
end try
end repeat
end adding folder items to
I'm using the var myFolder to search the file using the "Go To the folder"
The var myFolder works but only gives me the path to the folder, and I need the path to the folder + File.ext
Any help will be much appreciated/
Thanks/.
If I well understand what you want to so, you want to open with Uploader HD application each file which is just added into a specific folder.
If this is correct, then just use Folder actions. each time new files will be added to the folder, the system will trigger the script, giving as argument only the files just added (and not the file already stored in that folder previously !). for each file added, you must just ask HD uploader to open it.
You must first assign the script bellow to your folder "Update" :
Copy / paste the script bellow into ScriptEditor and save it in your ~library/Scripts/Folder Action Scripts
Right click on your folder (updates") and add this folder action script.
on adding folder items to myFolder after receiving FileList
repeat with aFile in FileList
tell application "Uploader HD for Instagram" to open aFile
end repeat
end adding folder items to
I can't test with Instagram uploader (I don't have it). It could happen that some applications are not answering to an "open" command. If this is the case you may have to replace the line "tell application...open aFile" by an other method to open it. You can use the variable aFile which contains the complete path to the added file. aFile is an alias type and (aFile as string) is the string which you can use in your goto dialog box.
Here is the final working code, what I was missing is POSIX
The var myFilePath defined with set includes the full path to the file
on adding folder items to myFolder after receiving FileList
try
repeat with i from 1 to number of items in FileList
repeat with aFile in FileList
activate application "Uploader HD for Instagram"
delay 0.5
delay 0.5
tell application "System Events"
tell process "Uploader HD for Instagram"
click menu item "Open..." of menu 1 of menu bar item "File" of menu bar 1
end tell
end tell
delay 0.5
set myFilePath to POSIX path of item i of FileList
tell application "System Events"
keystroke "G" using {command down, shift down}
delay 0.5
keystroke myFilePath
delay 0.5
keystroke return
delay 0.5
keystroke return
delay 0.5
keystroke tab
keystroke "#Instagood #Instagram #Luxury #Babe #Model #Follow #CindyJordanLove"
end tell
tell application "System Events"
tell process "Uploader HD for Instagram"
click button "Post" of window "Uploader HD for Instagram"
delay 1
tell application "Uploader HD for Instagram"
quit
end tell
end tell
end tell
try
tell application "Finder"
delete (every item of folder myFolder whose name ends with ".jpg")
end tell
on error
display dialog ("Error. Couldn't Move the File") buttons {"OK"}
end try
end repeat
end repeat
end try
end adding folder items to

Apple Script that copies/pastes text is broken in Yosemite

I made a simple AppleScript that copies the layer names from Photoshop and pastes them into Illustrator. It worked fine in Mountain Lion but now it doesn't work properly in Yosemite. It repeats 6 times, but it doesn't seem to activate Illustrator on the first run through. It does activate Illustrator the other 5 times it repeats. Here it is:
repeat 6 times
tell application "Adobe Photoshop CC 2014" to activate
tell application "System Events"
tell process "Photoshop"
keystroke "/" using command down
keystroke "c" using command down
keystroke tab
end tell
end tell
delay 0.3
tell application "Adobe Illustrator" to activate
tell application "System Events"
tell process "Illustrator"
keystroke "v" using command down
keystroke return
keystroke "-"
keystroke space
end tell
end tell
end repeat
end
Thanks for any help!
tell application "System Events" to repeat 6 times
tell process "Photoshop" to repeat until frontmost is true
set frontmost to true
delay 1
end repeat
keystroke "/" using command down
keystroke "c" using command down
keystroke tab
tell process "Illustrator" to repeat until frontmost is true
set frontmost to true
delay 1
end repeat
keystroke "v" using command down
keystroke return
keystroke "-"
keystroke space
end repeat

How to Populate Pages file from Excel Worksheet using Applescript

I'm trying to populate a template from data in an Excel spreadsheet. This is my first foray into Applescript. My plan is to have unique text strings in the template (i.e. Value_1, Value_2, etc) then store each value in a variable and find and replace each variable with each string.
I would very much appreciate any help; here is where I'm at:
tell application "Microsoft Excel"
tell active workbook
activate object worksheet "Page 2"
copy range range "B7" of active sheet
// Store as variable?
end tell
end tell
tell application "Pages"
activate
tell application "System Events"
keystroke "v" using command down
// Find and replace?
end tell
end tell
Something like this will do what you want :
tell application "Microsoft Excel"
tell active workbook
activate object worksheet "Sheet2"
set B7_Value to string value of range "B7" of active sheet
end tell
end tell
tell application "Pages"
set my_text to first document's body text
set temp to do shell script "echo " & quoted form of my_text & " | sed -e 's/B7_Value/" & B7_Value & "/g'"
set first document's body text to temp
end tell
This script does not keep formatting. If you want to keep formatting perhaps something like this :
tell application "Microsoft Excel"
tell active workbook
activate object worksheet "Sheet2"
set B7_Value to string value of range "B7" of active sheet
end tell
end tell
tell application "Pages"
activate
tell application "System Events"
keystroke "f" using command down
set the clipboard to "B7_Value"
keystroke "v" using command down
delay 0.1
keystroke tab
delay 0.1
set the clipboard to B7_Value
keystroke "v" using command down
delay 0.1
keystroke tab
delay 0.1
keystroke space
delay 0.1
key code 53 -- escape
end tell
end tell
For this to work you will need to enable System Preferences --> Keyboard --> All controls.

applescript click every element via gui scripting

I'd like to iterate through every element on an iTunes window and try to click on each element.
I'd also like to write to a text file showing each element that I've clicked.
The code that I wrote below isn't working. Specifically, I get the error process "iTunes" doesn’t understand the click_an_element message.
Thoughts on what I'm doing wrong?
Thanks!!
tell application "iTunes" to activate
tell application "System Events"
tell process "iTunes"
set elements to get entire contents of window "iTunes"
repeat with i from 1 to (length of elements)
set ele to item i of elements
click_an_element(ele)
show_what_you_clicked(ele)
end repeat
end tell
end tell
-------handlers------------
to click_an_element(an_element)
tell application "iTunes" to activate
tell application "System Events"
tell process "iTunes"
try
click an_element
end try
end tell
end tell
end click_an_element
to show_what_you_clicked(thing_to_type)
tell application "TextEdit" to activate
tell application "System Events"
tell process "TextEdit"
keystroke thing_to_type
key code 36
end tell
end tell
end show_what_you_clicked
your out of scope it thinks click_an_element is an itunes function
you need to add "my" to that call
Edit: since a had some time over lunch I play around with this a little bit had to turn off clicking because it was clinking minimize button then not giving access to the other items
tell application "iTunes" to activate
tell application "System Events"
tell process "iTunes"
set elements to get entire contents of window "iTunes"
end tell
repeat with i from 1 to (length of elements)
set ele to item i of elements
--my click_an_element(ele)
my show_what_you_clicked(description of ele)
end repeat
end tell
-------handlers------------
to click_an_element(an_element)
tell application "iTunes" to activate
tell application "System Events"
tell process "iTunes"
try
click an_element
end try
end tell
end tell
end click_an_element
to show_what_you_clicked(thing_to_type)
tell application "TextEdit" to activate
tell application "System Events"
tell process "TextEdit"
keystroke thing_to_type
key code 36
end tell
end tell
end show_what_you_clicked

Resources