Form Fill Paste then Tab Repeat - forms

I am trying to script some data entry using a applescript.
I need it to paste and then tab seven times and then paste again..... 2700 times.
While I am very new to programming, I was at least able to get something working.
What I have so far:
set the clipboard to "blah"
tell application "blah"
activate
tell application "System Events"
repeat 4 times
keystroke "v" using {command down}
keystroke " "
end repeat
end tell
end tell
Now this will paste into the first form and then skip one and paste into the next one. I dont know why. So this just pastes into every other form.
Any help?

Try:
set the clipboard to "blah"
tell application "blah"
activate
tell application "System Events"
repeat 4 times
keystroke "v" using {command down}
delay 1
repeat 7 times
keystroke tab
delay 1
end repeat
end repeat
end tell
end tell

Related

Autohotkey loop down key/folder-files

I want to add +1 to {Down} after starting the next loop
F8::
stop := 0
Loop, 13
{
Run, "C:\Users\USER\Desktop\docs"
Send {Home}
Sleep 1000
Send {Down} ;Here i want to add +1 after loop start again
Sleep 2000
Send {Enter}
Sleep 2000
Send !{F11}
Sleep 2000
Send {F5}
Sleep 2000
Send !{f4}
Sleep 2000
}until Stop
return
F9::Stop := 1
If someone has a different solution how to open files one by one and perform a given action and add it in a loop, please give me some suggestions.
OK i know the answer
Send, {Down %A_index%}
What i want to do. So I want to Open folder with some texts files (MS Word) and open first one, klick macro (alt+f11) then start macro (f5) and klick (alt + f4) to close macro window and next (alt+f4) to close word window then klick twice enter to accept save changes, then start loop again with next document (loop time = x documents in folder). But im done right now ;p
Anyway if u have any other idea how do things like this in future u can tell ;p
PS Add+1 dostn work ;p

Automatic translation

im really new to all this and i was trying to make an Autohotkey for translation. i was digging for some time looking for examples that only confused me more, even if the code looked simple, i didn't understand half of it.
So, what I'm trying to do is: select a paragraph and replace it automatically with its translation.
i was hooping it to be somenthing as simple as CTRJ + C, Translate, CTRL + V, but i can't find the command to go to google translate or somenthing similar, it's not on the autohotkey help file so i'm guessing i don't have libraries?
I'm at my wits end, please help.
You came to the right place. Check out AutoHotKey for sure.
First, how to do it by hand? Those are the steps for ahk. So, lets say you have a paragraph of text selected. You will hit the ahk shortcut and that shortcut will:
first ahk figures out what window its in (using WinGetActiveTitle) and then sends the keystrokes Ctrl+c to copy the selection ("send, ^c" and "Clipwait"), then
ahk can access the clipboard containing the text, do a string manipulation or regex to replace all spaces with the html escape sequence %20 (eg, transtext := StrReplace(Clipboard, " ", "%20")) and
construct a URL to do the Google Translate, something like (where sl is source language and tl is translation language, and text is what you want translated): transurl := "https://translate.google.com/#view=home&op=translate&sl=en&tl=es&text=" . transtext
AHK runs that url and opens a browser window showing result (run % transurl).
This part sucks. Now, you need to use a mouse click at a location (or maybe you can find a controlsend or a combination of keystrokes moving the cursor with tabs and such) to land on the "Copy translation" button. Or how bout you do it manually (try sleep, 8000 to wait while you hit the button)
then have ahk close the window (optionally, or you just do it by hand during the sleep time) and
ahk switches back to the application with the original selected paragraph (WinActivate or do it yourself) and
send ctrl+v to paste the translated text over the original (send ^v).
A starter pack of AHK code (edited per user comments):
WinGetActiveTitle, activewin
Clipboard =
SendInput, ^c
ClipWait
transtext := StrReplace(Clipboard, " ", "%20")
transurl := "https://translate.google.com/#view=home&op=translate&sl=en&tl=es&text=" . transtext
Run, % transurl
Sleep, 6000 ; adjust to taste.
SendEvent, {tab 10} ; adjust to taste.
Sleep 1000
SendInput, {enter}
Sleep, 1000
SendInput, ^{F4}
WinActivate, activewin
sleep, 1000
SendInput, ^v
Try it and let us know how else to help.
OKOK, first of all, thank you all, the script works just fine now. I'm able to copy, translate and paste any text now. Only a few questions lingering.
1) i'm not sure i get what the step number 5 is suppose to do. whatever it is, it works so i don't touch it.
2) is there a way to reset google.translate so it dosent open a new window every time? that could save a lot of time.
3) this one doesn't have a chance, but i ask anyway. Is there a way to not open google chrome at all? because i know that u can translate from excel automatically. (i know that if it is possible will be super hard)
This is the code i ended with:
^a::
clipboard := ""
sendinput, ^c
ClipWait [,,Waitforanydata]
transtext := StrReplace(Clipboard, " ", "%20")
transurl := "https://translate.google.com/#view=home&op=translate&sl=en&tl=es&text=" .
transtext
run % transurl
Sleep, 4000
SendEvent, {tab 9}
SendEvent, {enter}
Winactivate, NAME.pdf - PROGRAM
sendinput, ^v

Avoiding loop when Double pressing same shortcut key without changing original 1 press shortcut key function (Autohotkey)

I want to produce something like this :
1. When i press Esc 2 times (double) i want to produce my "made-up custom action"
2. When i press Esc 1 time i want to produce the original Escape
ok, here is the explanation of my question :
This code should apply as global, means when i start the script it will work on all windows
%ALAT1% is variable the Active Windows title , abbreviation "Anime Land Akui Transform" some kind of silly anime game
If i press Esc one time . it will "pause" the game, but when i press Esc 2 times, it will "exit" the game"
I want to do a custom action when i press Esc 2 times, but i also don't want the original Esc key function got override when i press 1 time.
Escape::
if (A_PriorHotkey = A_ThisHotKey and A_TimeSincePriorHotkey < 400)
WinActivate, %ALAT1%
IfWinActive, ahk_class TscShellContainerClass
{
Send {F5} ; F5 contains another action
}.
else
{
*Do original function of Escape i.e Send {Escape} ; Now this is the problem
}
return
after i try the code above : suppose i press "Escape" button it will loop the Escape as if i press Escape 2 times. So my real question is how to make "original 1 times press Esc key function" won't loop to "our custom 2 times press Esc key function" ?
Change the first line of your code to;
$Escape::
This will set it so that the hotkey is only triggered by real keystrokes not simulated ones.

Trying to get the contents of an email message in AppleScript without added characters

Okay, I need to add some emails to my Daylite tasks automatically based on certain criteria, so I set up a Mail.app rule and an AppleScript to accomplish this. There's only one problem: when the AppleScript gets the content of the message, it adds an 'a' at the end (and makes a beep as well, letting me know it tried some keystroke that apparently wasn't allowed).
Here's what the AppleScript looks like:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with eachMessage in theMessages
try
set this_subject to subject of eachMessage
set this_body to content of eachMessage
if this_subject is "" then error
on error
set this_subject to "No subject."
end try
activate application "Daylite"
tell application "System Events"
keystroke "t" using {command down, shift down}
keystroke this_subject
keystroke tab
keystroke this_body
keystroke "s" using command down
end tell
end repeat
end tell
end perform mail action with messages
end using terms from
This results in me getting a new task in Daylite, where the task title is the email Subject, and is displayed correctly, but the attached note, which is the email's body, is not displayed correctly.
So, if I receive an email that matches my rule, and the email is:
From: Hypothetical Wife
Subject: Don't forget to take out the trash!
Body: If you forget one more time, I'm filing for a divorce.
That ends up with a task that looks like this:
☐ Don't forget to take out the trash!
If you forget one more time, I'm filing for a divorce.a
… making my hypothetical wife in this scenario sound like a barely literate Canadian. (Plus there's an system alert sound, letting me know it apparently tried to type something that's not allowed.)
If the body has multiple lines of text, it also annoyingly removes the line-breaks.
I know I could set it to:
set the clipboard to this_body
and then replace
keystroke this_body
with
keystroke "v" using command down
…but that's a really inelegant solution and I don't want to replace whatever's in my clipboard every time the rule runs.
What am I doing wrong here? I've tested this in TextEdit as well, and the same problem occurs there too, so it's not a Daylite problem. I've also tried appending "as Unicode text" or "as string" or "as «class UTF8»" to the end of the "set this_body…" line, but none of those fixed the problem either.
Please, explain it to me like I'm a complete idiot because, as a complete idiot, that's the only way I'll understand you. Thanks.
One of the basic mistakes many people make is telling an application to do things that the application does not know how to do. You should only tell an application to do things that you can find in its applescript dictionary because that's really all the application knows how to do... besides some basic general purpose applescript stuff like performing a repeat loop.
You have fallen into this trap. You are telling Mail to tell Daylight and System Events to do things because all of that code is inside the "tell application Mail" block of code. This type of error often leads to problems that are very difficult to track down.
As such, my first suggestion would be to stop telling Mail to do unnecessary things. Here's how I would write your code to separate the different application commands from each other.
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with eachMessage in theMessages
tell application "Mail"
set this_subject to subject of eachMessage
set this_body to content of eachMessage
end tell
if this_subject is "" then set this_subject to "No subject."
activate application "Daylite"
delay 0.2
tell application "System Events"
tell process "Daylite"
keystroke "t" using {command down, shift down}
delay 0.2
keystroke this_subject
delay 0.2
keystroke tab
delay 0.2
keystroke this_body
delay 0.2
keystroke "s" using command down
end tell
end tell
end repeat
end perform mail action with messages
end using terms from
You'll also notice I added a small delay between some of your code. Sometimes the code runs more quickly than the computer interface can handle, so that too may be a source of your error. You can also try increasing the length of the delay if needed (any delay over 1 second is overkill and shouldn't be necessary).
If these changes and a longer delay don't work then a simple solution would be to check if the text ends with "a" and just remove it. Something like this between the keystroke tab and keystroke this_body lines...
if this_body ends with "a" then set this_body to text 1 thru -2 of this_body
Good luck!
EDIT: the "keystroke" process doesn't seem to like the return characters from the email. I believe that's what causing the noise... when it hits a return character it beeps. Anyway, you can try something like this. Just open a blank TextEdit document and select an email in Mail and run the code in AppleScript Editor. You can incorporate this idea in your Daylight script.
tell application "Mail"
set eachMessage to item 1 of (get selection)
set this_subject to subject of eachMessage
set this_body to content of eachMessage
end tell
set bodyList to paragraphs of this_body
activate application "TextEdit"
tell application "System Events"
tell process "TextEdit"
repeat with i from 1 to count of bodyList
keystroke (item i of bodyList)
keystroke return
end repeat
end tell
end tell

Saving a mail message in applescript

I'm new to applescript and I'm having enormous trouble doing something which seems very basic. I'm trying to save a selected mail message in RTF format with attachments. Here is the errant script:
tell application "Mail"
activate
set AllMessages to selection
set myMessage to item 1 of AllMessages
open myMessage
tell application "System Events"
tell process "Mail"
tell menu bar 1
tell menu bar item "File"
tell menu "File"
click menu item "Save As…"
delay 2
keystroke "test"
click checkbox "Include Attachments" -- result: ERROR
end tell
end tell
end tell
end tell
end tell
end tell
You can try something like this:
set the clipboard to POSIX path of (path to desktop as text) & "test"
tell application "Mail"
open first item of (get selection)
activate
end tell
tell application "System Events"
tell process "Mail"
click menu item "Save As…" of menu 1 of menu bar item "File" of menu bar 1
delay 3
perform action "AXPress" of pop up button 1 of group 1 of sheet 1 of window 1
click menu item 1 of menu 1 of pop up button 1 of group 1 of sheet 1 of window 1
if value of checkbox "Include Attachments" of group 1 of sheet 1 of window 1 = 0 then
perform action "AXPress" of checkbox "Include Attachments" of group 1 of sheet 1 of window 1
end if
keystroke "g" using {command down, shift down}
keystroke "v" using {command down}
keystroke return
keystroke return
end tell
end tell