AppleScript C Perl Shell Xcode Other

Login and post to Ping.fm - Social Networks

Post Reply
coding / applescript     Views: 2100Prev .. Next
Login and post to Ping.fm - Social NetworksPosted: Tuesday, June 22, 2010 [19:27:24] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
You could distribute your content to a Social Networks using Ping.fm by linking your RSS to Superfeedr, post them manually or email to your pre-set ping.fm address.

If none of the above works or you just could not provide content on time - you could tell your Mac to Login to Ping.fm and post your message VIA Dashboard.

Skeptical? Don't be. Here is an AppleScript:
View Codetell application "Safari" to activate
delay 3
tell application "System Events"
tell application process "Safari"
-- make sure and Java is enabled in Safari
keystroke "," using {command down}
delay 4
get value of static text 1 of window 1
copy the result as string to varWindowName
click button "Security" of tool bar 1 of window varWindowName
delay 2
get value of checkbox "Enable Java" of group 1 of group 1 of window "Security"
copy the result as number to varResult
if varResult = 0 then
click checkbox "Enable Java" of group 1 of group 1 of window "Security"
end if
get value of checkbox "Enable " of group 1 of group 1 of window "Security"
copy the result as number to varOption
if varOption = 0 then
click checkbox "Enable " of group 1 of group 1 of window "Security"
end if
delay 2
click button 1 of window "Security"
end tell
end tell

set godoNext to false

tell application "Safari"
make new document
delay 2
set URL of document 1 to "https://www.ping.fm/"
set myURL to URL of document 1
delay 10
set web_page_is_loaded to false
set myCounter to 0
set maxCounter to 30
set my_delay to 2
repeat until web_page_is_loaded is true
if name of window 1 contains "Loading" or name of window 1 contains "Untitled" then
delay my_delay
else
set godoNext to true
set web_page_is_loaded to true
end if
set myCounter to myCounter + 1
if myCounter is maxCounter then
set web_page_is_loaded to true
end if
end repeat
end tell
delay 1

if godoNext is true then

tell application "Safari"

set LinkPresent to ""
set LinkPresent to (do "document.links.length" in document 1)
set LinkPresent to LinkPresent - 1
set Split to ""
repeat with n from 0 to LinkPresent
set linkURL to (do "document.links[" & n & "].href" in document 1)
set linkName to (do "document.links[" & n & "].text" in document 1)
if linkName contains "Login" then
do "document.links[" & n & "].focus();" in document 1
delay 2
tell application "System Events"
tell application process "Safari"
keystroke return -- login page
delay 8
end tell
end tell
exit repeat
end if
end repeat

end tell -- end Safari tell
-- now login to your Ping.fm account
set logged to makeLogin()

if logged is true then

tell application "Safari"
do "document.getElementById('message').focus()" in document 1
delay 3
tell application "System Events"
tell application process "Safari"
keystroke "Your_Message_here"
keystroke return
delay 1
keystroke "Your_Message_here_continues"
delay 5
keystroke tab
delay 2
keystroke return
delay 5
end tell
end tell
end tell
delay 15

-- Logout
tell application "Safari"
set LinkPresent to ""
set LinkPresent to (do "document.links.length" in document 1)
set LinkPresent to LinkPresent - 1
set Split to ""
repeat with n from 0 to LinkPresent
set linkURL to (do "document.links[" & n & "].href" in document 1)
set linkName to (do "document.links[" & n & "].text" in document 1)
if linkName contains "LogOUT" then
do "document.links[" & n & "].focus();" in document 1
delay 2
tell application "System Events"
tell application process "Safari"
keystroke return -- login page
delay 8
keystroke "q" using {command down}
delay 3
end tell
end tell
exit repeat
end if
end repeat
end tell

do shell script "touch /ping.sent.now.txt"

else -- end logged

tell application "System Events"
tell application process "Safari"
keystroke "q" using {command down}
delay 3
end tell
end tell

end if -- end not logged

else -- end if go ahead is true

tell application "System Events"
tell application process "Safari"
keystroke "q" using {command down}
delay 3
end tell
end tell
end if -- end no go reported as main page was not loaded

on makeLogin()
delay 2
repeat with j from 0 to 2
tell application "System Events"
tell application process "Safari"
key code 53 -- stop loading page
delay 2
keystroke "a" using {command down}
delay 2
keystroke "c" using {command down}
delay 2
set htmlSrc to (the clipboard) as text
delay 1
end tell
end tell

if htmlSrc contains "login" then
doLogin()
else -- end still not logged
return true
exit repeat
end if -- end logged
delay 2
end repeat
end makeLogin

on doLogin()
tell application "Safari"
do "document.getElementById('sv').focus()" in document 1
delay 1
tell application "System Events"
tell application process "Safari"
keystroke tab using {shift down}
delay 1
keystroke tab using {shift down}
delay 1
-- this portion has to be generated from database or so
-- Content of your message
keystroke "Your_Ping.fm_Email_to_Login"
delay 2
keystroke tab
delay 1
keystroke "Your_Ping.fm_Password"
delay 3
keystroke return
delay 2
-- your message posted
end tell
end tell

-- See if page is loaded
delay 2
set page_is_loaded to false
set rdCounter to 0
set mrCounter to 30
set pg_delay to 1
repeat until page_is_loaded is true
if name of window 1 contains "Loading" or name of window 1 contains "Untitled" then
delay pg_delay
else
set page_is_loaded to true
end if
set rdCounter to rdCounter + 1
if rdCounter is mrCounter then
set page_is_loaded to true
end if
end repeat

end tell
end doLogin

You have to create this code with a language of your choice (Perl, PHP or any other) and run it.
Obviously content has to come from somewhere, i.e. database, email, web page or so.

From Perl you can run this AppleScript as: `osascript /Your.AppleScript.scpt`;
and after running it - just delete it: unlink '/Your.AppleScript.scpt';There's no place like ~
AdditionPosted: Tuesday, June 22, 2010 [19:36:03] - 2
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
Login procedure runs in a loop as Ping.fm for some reason do not let Safari login to your account on first try even with proper credentials, so I had to write a loop and check if login was successful.There's no place like ~
coding / applescriptPrev .. Next
 
Post Reply
Home - Coding: AppleScript C Perl Shell Xcode Other
Our Telegram Group