AutoHotkey Community

It is currently May 27th, 2012, 5:44 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: March 16th, 2010, 4:29 pm 
Offline

Joined: November 17th, 2009, 3:19 pm
Posts: 12
I send a lot of common responses via email so I want to create a GUI to select and paste canned answers into emails.

This is the first GUI I've attempted and the more I think about it, the more trouble I have wrapping my head around the execution.

What I want to do:

Build a GUI with a drop down list and a submit button. The drop down list would contain a list of common replies. Each item in the list would correspond with a block of text to be pasted into the email. The items in the dropdown list would be in the following format: How to register | How to access archives | How to log on | Etc...

The user should select an item from this list and press the submit button. Upon pressing Submit, the script would paste the block of text associated with the selected item from the drop down list and then close the GUI.

The GUI would be called using a hotstring entered into a blank reply to the original email.

What I'm trying to wrap my head around:

When the user presses the submit button, it would store the selected item as a variable (vCanned) - right? I imagine the script would need an IF statement, that would say something like this:

if vCanned="How to register"
SendInput, BIG BLOCK OF TEXT HERE

else if vCanned="How to access archives"
SendInput, ANOTHER BLOCK OF TEXT WOULD GO HERE

else if vCanned="How to log on"
SendInput, YET ANOTHER BLOCK OF TEXT

and so on...


My question:

Am I on the right track here? I have a feeling I'm completely wrong in how I am trying to do this. Can someone give me an idea of the concepts I should be looking at?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2010, 5:06 pm 
Offline

Joined: May 12th, 2009, 2:37 pm
Posts: 640
Location: Gloucester UK
You are definately on the right track. A couple of things to mention would be that in your if statements you don't need the small v

Code:
If Caned="How to register
          Send, BIG BLOCK OF TEXT HERE


While your If statement method will definitely work, you might consider a slightly different approach to allow for easy changing of the text that is sent.

I would create a sperate .txt file for each reply. I would name each of them with the description contained in the drop down list

eg. How to register.txt
How to access archives.txt

This would be beneficial for two reasons.

1. To change the text you need only edit that text file rather than the ahk code. This could be useful if other people wanted to use your application as they could personalise the replies without accessing the code

2. the only code that would be needed after your submit button would be

Code:
ButtonSubmit:
Gui, Submit
FileRead, Answer_Text, %Canned%.txt
SendInput, %Answer_Text%
Return


which makes the whole thing easier to maintain


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 16th, 2010, 5:11 pm 
Offline

Joined: March 8th, 2010, 3:55 pm
Posts: 11
factory wrote:
Am I on the right track here? I have a feeling I'm completely wrong in how I am trying to do this. Can someone give me an idea of the concepts I should be looking at?

I think you are on the right track. but I am not really sure.
you could try the blow script:
Code:
if (vCanned="How to register")
SendInput, BIG BLOCK OF TEXT HERE

else if (vCanned="How to access archives")
SendInput, ANOTHER BLOCK OF TEXT WOULD GO HERE

else if (vCanned="How to log on")
SendInput, YET ANOTHER BLOCK OF TEXT

It have been tested. but still have a little unstable.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2010, 8:00 pm 
Offline

Joined: November 17th, 2009, 3:19 pm
Posts: 12
Thanks for the advice. This is is helpful information. I'll plug away at it to see if I can figure it out.

I might be back though :oops:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 2:41 pm 
Offline

Joined: November 17th, 2009, 3:19 pm
Posts: 12
wooly_sammoth wrote:
I would create a sperate .txt file for each reply. I would name each of them with the description contained in the drop down list

eg. How to register.txt
How to access archives.txt

This would be beneficial for two reasons.

1. To change the text you need only edit that text file rather than the ahk code. This could be useful if other people wanted to use your application as they could personalise the replies without accessing the code

2. the only code that would be needed after your submit button would be

Code:
ButtonSubmit:
Gui, Submit
FileRead, Answer_Text, %Canned%.txt
SendInput, %Answer_Text%
Return


which makes the whole thing easier to maintain



I liked your solution so I went with it. I'm encountering an odd problem though. For some reason it takes two presses of my Submit button to paste the text of the file.

Here's the script:

Code:
:*:;can::
;show user input box
Gui, Destroy
Gui, Font, Arial
Gui, Add, Text,, Select Response
Gui, Add, DropDownList, W200 vCanned, How to Register|How to Log On|Accessing Digital Edition|Research Request Guidelines|
Gui, Add, Button, W100 X220 Y25 , Submit
ButtonSubmit:
Gui, Submit
FileRead, Answer_Text, %Canned%.txt
SendInput, %Answer_Text%

Gui, Show, W350 H80, Can Opener


Any idea why it's not pasting on the first press of the button?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 4:06 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
try this

Code:
:*:;can::
;show user input box
Gui, Font, Arial
Gui, Add, Text,, Select Response
Gui, Add, DropDownList, W200 vCanned, How to Register||How to Log On|Accessing Digital Edition|Research Request Guidelines|
Gui, Add, Button, W100 X220 Y25 , Submit
Gui, Show, W350 H80, Can Opener
Return

ButtonSubmit:
   Gui, Submit
   Gui, Destroy
   FileRead, Answer_Text, %Canned%.txt
   SendInput, %Answer_Text%
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 4:16 pm 
Offline

Joined: November 17th, 2009, 3:19 pm
Posts: 12
That works perfectly - thanks much!

So was it the lack of Return in my script which caused the double pressing of the button?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 4:23 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
factory wrote:
So was it the lack of Return in my script which caused the double pressing of the button?


Yes, basically if you don't return then the script will "fall through" the label and execute everything until it hits a return.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2010, 3:17 pm 
Offline

Joined: November 17th, 2009, 3:19 pm
Posts: 12
Thanks for all the help with this. The GUI is working well and has sped up my productivity.

However, I have a new question:

Is there a way to have variable text within the .txt files I am inserting?

For example, we have multiple websites and sometimes I need to refer to one a specific site in my reply.

Once a .txt file is inserted from the GUI, is there a way to have an option of which website name to insert into a specified place in the inserted text?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2010, 3:46 pm 
Offline

Joined: May 12th, 2009, 2:37 pm
Posts: 640
Location: Gloucester UK
You could have a place holder within the text. Something like $website
Once you've called the text from the file you can scan it for the place holder and replace it with the specified string.

something like this:

Code:
Website = example.com
FileRead, Gui_Text, Text_File.txt
IfInString, Gui_Text, $Website
{
          StringReplace, Gui_Text, Gui_Text, $Website, %Website%, A
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 31st, 2010, 2:00 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3330
Location: Simi Valley, CA
Transform, EmailText, DEREF, %TemplateWithVariables%

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 31st, 2010, 2:54 pm 
Offline

Joined: November 17th, 2009, 3:19 pm
Posts: 12
[VxE] wrote:
Transform, EmailText, DEREF, %TemplateWithVariables%


Sorry to be dense, but could you please elaborate on this? For example, where would this be inserted into the code? Also, what would I do with %TemplateWithVariables%?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Bing [Bot], Google Feedfetcher, mrhobbeys, rbrtryn and 59 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group