AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Update Twitter via Launchy & AHK

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Voltron43



Joined: 27 Mar 2009
Posts: 76
Location: Dublin, IE

PostPosted: Fri Jun 05, 2009 8:54 pm    Post subject: Update Twitter via Launchy & AHK Reply with quote

I was searching for some more things to do with Launchy, the open source keystroke launcher, and I came across an old Lifehacker article explaining how to update your Twitter status using Launchy, curl and a batch script.

I don't like using using curl, so I made a script instead using httpQuery.

DIRECTIONS
    1. Save the twit.ahk script to a directory.

    2. Enter your Twitter UserName and Password into the script.
Code:
UserName := "UserName"
Password := "Password"

    3. Add the directory to Launchy's Catelog and add *.ahk to the extensions



    4. Type twit in the Launchy bar and then press Tab and type your Twitter status.



    5. Voilą



twit.ahk
Code:
; ==============================================================================
; NAME:         twit.ahk
; VERSION:      v0.1.0
; DESCRIPTION:  Update Twitter status via Launchy
;
; AUTHOR:       Voltron43
; HOMEPAGE:     http://autohotkey.net/~Voltron43
; ==============================================================================
;
; ---Construct Status message from passed parameters
Loop, %0%
    Status := A_Index = 1 ? %A_Index% : Status " " %A_Index%

; ---Check to make sure Status is shorter than 140 characters
If StrLen(Status) > 140
{
    MsgBox, 32,,Status is too long!
    ExitApp
}
UserName := "UserName"
Password := "Password"
URL := "http://" UserName ":" Password "@twitter.com/statuses/update.xml?"
POSTdata := "status=" Status
length := httpQUERY(buffer:="",URL,POSTdata)
VarSetCapacity(buffer, -1)

; ---Check for error
If buffer contains status
    MsgBox, 32,, Status Update Complete!
Else
    MsgBox, 32,, Twitter Error!

#Include httpQuery.ahk

_________________
My Scripts
Back to top
View user's profile Send private message Visit poster's website
Vamsi
Guest





PostPosted: Tue May 10, 2011 7:34 am    Post subject: Error Reply with quote

I have downloaded the httpQuery.ahk too for the include directive. Messagebox throws a twitter error, I wonder why! Inspite of typing in the status in launchy. Strangely, It is going into the if condition if I exceed the 140 limit but if it is less, the buffer is not getting filled with the status. Please help me.
Back to top
sumon



Joined: 18 May 2010
Posts: 1008
Location: Sweden

PostPosted: Tue May 10, 2011 8:17 am    Post subject: Reply with quote

My guess is that Twitter only supports oAuth. Octal said in this post that he is working on a solution.

As for me, Tweeting is one of the more useful things that I would like to integrate directly in front of my nose, instead of having to go to a website to do it.
Back to top
View user's profile Send private message Visit poster's website
fragman



Joined: 13 Oct 2009
Posts: 1187

PostPosted: Tue May 10, 2011 9:10 am    Post subject: Reply with quote

Hmm, interesting...
If this works I'd like to integrate it in my Accessor launcher in 7plus,
I suggest using COM for sending the data though. There should be an example for using the COM interface in the COM reference thread I think.
Back to top
View user's profile Send private message
Sky



Joined: 01 Apr 2011
Posts: 59
Location: California

PostPosted: Tue Jul 05, 2011 3:59 am    Post subject: Reply with quote

Hmmmm This is very interesting. I was wondering if anyone could explain to me how the first few lines of code (specifically the loop with %0%) works? I understand that it takes whatever you typed into launchy and saves it as "status" but i cant figure out how it goes about doing that. Very useful script. Thanks Voltron43
Back to top
View user's profile Send private message
nfl
Guest





PostPosted: Tue Jul 05, 2011 8:36 am    Post subject: Reply with quote

@Sky:
The script is very simple, I'll explain it to you in the comments:
Code:
; ==============================================================================
; NAME:         twit.ahk
; VERSION:      v0.1.0
; DESCRIPTION:  Update Twitter status via Launchy
;
; AUTHOR:       Voltron43
; HOMEPAGE:     http://autohotkey.net/~Voltron43
; ==============================================================================
;
; ---Construct Status message from passed parameters
Loop, %0% ; variable 0 contains the number of parameters passed to the script, e.g. the numbers of words --> loop that often
    Status := A_Index = 1 ? %A_Index% : Status " " %A_Index% ; put the different words into a single string

; ---Check to make sure Status is shorter than 140 characters
If StrLen(Status) > 140
{
    MsgBox, 32,,Status is too long!
    ExitApp
}
UserName := "UserName"
Password := "Password"
URL := "http://" UserName ":" Password "@twitter.com/statuses/update.xml?" ; creates the url with username and password
POSTdata := "status=" Status ; this will be sent to the above url
length := httpQUERY(buffer:="",URL,POSTdata) ; send the status to twitter
VarSetCapacity(buffer, -1) ; convert the returned data to a string

; ---Check for error
If buffer contains status
    MsgBox, 32,, Status Update Complete!
Else
    MsgBox, 32,, Twitter Error!

#Include httpQuery.ahk

Just write back if you have further questions.
Back to top
Sky



Joined: 01 Apr 2011
Posts: 59
Location: California

PostPosted: Tue Jul 05, 2011 4:18 pm    Post subject: Reply with quote

Thanks nfl!
so I was wondering, is variable 0 sort of like a predefined variable used by launchy? I dont see it defined anywhere in the script. also for the starust part I understand that if %A_index%(word) = 1 then the status would be %A_index% because there was only 1 word. but if %A_index% is more than 1, how does status " " %A_index% join the words? is it looping and adding a space in between the %A_index%'s(word)?
sorry for the noobish questions. And thank you very much nfl for explaining the rest of the script to me Smile it was very helpful and im grateful
Back to top
View user's profile Send private message
fragman



Joined: 13 Oct 2009
Posts: 1187

PostPosted: Tue Jul 05, 2011 4:32 pm    Post subject: Reply with quote

0 is the number of command line arguments, 1 is the first one, 2 the second,...
For further information please refer to the help file.
Back to top
View user's profile Send private message
nfl
Guest





PostPosted: Tue Jul 05, 2011 5:57 pm    Post subject: Reply with quote

Sky wrote:
is variable 0 sort of like a predefined variable used by launchy? I dont see it defined anywhere in the script.

No, it's the number of arguments passed to the script. Look in the help file under "parameters passed into a script".

Sky wrote:
but if %A_index% is more than 1, how does status " " %A_index% join the words? is it looping and adding a space in between the %A_index%'s(word)?

It is joining the words, because there is
Code:
status := status " " %A_Index%

You could write the block like this:
Code:
Loop, %0% ; variable 0 contains the number of parameters passed to the script, e.g. the numbers of words --> loop that often
{
   if (A_Index = 1)
      Status := %A_Index%
   else
      Status := Status " " %A_Index%
      ; or my preferred way
      ; Status .= " " %A_Index%
}
Back to top
Sky



Joined: 01 Apr 2011
Posts: 59
Location: California

PostPosted: Tue Jul 05, 2011 7:29 pm    Post subject: Reply with quote

thanks fragman and nfl! thanks to you guys ill be able to work on some cool scripts with launchy. hopefully the community will find them useful :p
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group