8 Nisan 2012 Pazar

AppleScript Ornegi


MacOSX sistemlerde kullanicinin rutin islerini otomatize edebilmesi icin kullanimi oldukca kolay olan bir programlama arabirimi bulunmaktadir. Bu arabirimi kucuk bir uygulama ile gosterneye calisacagim. Daha ayrintili bilgiye ihtiyac duyanlar buradan faydalanabilirler.

herhangi bir lokasyondan internete baglandigimiz zaman, dis ip adresinizi ogrenmek isteyebilirsiniz. Bunun icin "AppleScript Editor" icerisine asagidaki kod parcacigini yaziyoruz. 

property theIP : ""
set TheResult to (do shell script "curl -f http://checkip.dyndns.org")
set Olddelim to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to "Current IP Address: "
set LongIP to item 2 of every text item of TheResult as text
set AppleScript's text item delimiters to ""
set stopPoint to (offset of "< " in LongIP)
set myip to characters 1 through (stopPoint - 1) of LongIP as text
if theIP is "" then
set theIP to myip
display dialog "Your IP is : " & myip
end if
if myip is not equal to theIP then
display dialog "Your IP is : " & myip
set theIP to myip
end if
set AppleScript's text item delimiters to Olddelim
on error
set AppleScript's text item delimiters to Olddelim
end try

istedigimiz betigi yazdiktan sonra derleyerek sistemde calismasini testedebiliyoruz. Daha sonrasinda bu uygulamayi kaydederek sistemde istedigimiz zaman calisir hale etirebilirz.

kaynaklar:

Hiç yorum yok:

Yorum Gönder