test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
property usernamePasswordString : ""
property tagsString : ""
 
on run
	checkUsernameAndPassword()
	postToDelicious()
end run
 
on postToDelicious()
	tell application "NetNewsWire"
		if exists selectedHeadline then
			set u to "\"?&url=" & (URL of selectedHeadline) & ¬
				"&description=" & (title of selectedHeadline) & ¬
				"&tags=" & tagsString & "\""
			set curlStatement to "/usr/bin/curl -u " & usernamePasswordString & " -d " & u & " https://api.del.icio.us/v1/posts/add"
			set retValue to do shell script curlStatement
			if retValue contains "wrong" then
				display dialog "Headline did not post to del.icio.us. Something went wrong."
			end if
		else
			display dialog "Please select a headline to post to del.icio.us"
		end if
	end tell
end postToDelicious
 
on checkUsernameAndPassword()
	-- Check to see if the file where our username and password are stored exists
	try
		do shell script "cd " & POSIX path of (path to preferences as text) & "; ls | grep com.larrystaton.toread.txt"
		try
			set prefFile to ((path to preferences as text) & "com.larrystaton.toread.txt")
			open for access file prefFile with write permission
			set prefs to read file prefFile using delimiter {return}
			close access file prefFile
			set usernamePasswordString to item 1 of prefs
			set tagsString to item 2 of prefs
		on error e
			close access file prefFile
		end try
	on error
		set username to text returned of (display dialog "Please enter your del.icio.us username" default answer "username")
		set pass to text returned of (display dialog "Please enter your del.icio.us password" default answer "password")
		set tags to text returned of (display dialog "Please enter any desired default tags" default answer "toread ")
		try
			set prefFile to ((path to preferences as text) & "com.larrystaton.toread.txt")
			open for access file prefFile with write permission
			set eof of file prefFile to 0
			write username & ":" & pass & {return} & tags to file prefFile
			close access file prefFile
		on error e
			close access file prefFile
		end try
		set usernamePasswordString to username & ":" & pass
		set tagsString to tags & " "
	end try
end checkUsernameAndPassword

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.