Help Completing / Coding Droplet for Tweeting via Twitter Scripter

Did a bit of cleaning

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) samedi 8 juillet 2017 14:32:34

Here are the results from the test run. I will answer your earlier questions separately.

One thing to note is the images must be loaded from the Pictures folder, which I am doing when running the droplet.


tell current application
	path to library folder from user domain as text
		--> "Macintosh HD:Users:????:Library:"
	read file "Macintosh HD:Users:????:Library:Application Support:tweetIndex_xednIteewt.txt"
		--> "2"
	path to frontmost application as string
		--> "Macintosh HD:Applications:Utilities:Script Editor.app:"
end tell
tell application "Script Editor"
	display dialog "fake tweet :\n#HappyDays more testing of desktop tweets\nto : fakeAccountID\n with picture : file1"
		--> {button returned:"OK"}
end tell
tell current application
	path to frontmost application as string
		--> "Macintosh HD:Applications:Utilities:Script Editor.app:"
end tell
tell application "Script Editor"
	display dialog "fake tweet :\nFollow the tweeting challenge\nto : fakeAccountID\n with picture : file2"
		--> {button returned:"OK"}
end tell
tell current application
	path to frontmost application as string
		--> "Macintosh HD:Applications:Utilities:Script Editor.app:"
end tell
tell application "Script Editor"
	display dialog "fake tweet :\nTesting Tweets from my desktop again\nto : fakeAccountID\n with picture : file3"
		--> {button returned:"OK"}
end tell
tell current application
	path to frontmost application as string
		--> "Macintosh HD:Applications:Utilities:Script Editor.app:"
end tell
tell application "Script Editor"
	display dialog "fake tweet :\n#HappyDays more testing of desktop tweets\nto : fakeAccountID\n with picture : file4"
		--> {button returned:"OK"}
end tell
tell current application
	path to frontmost application as string
		--> "Macintosh HD:Applications:Utilities:Script Editor.app:"
end tell
tell application "Script Editor"
	display dialog "fake tweet :\nFollow the tweeting challenge\nto : fakeAccountID\n with picture : file5"
		--> {button returned:"OK"}
end tell
tell current application
	path to frontmost application as string
		--> "Macintosh HD:Applications:Utilities:Script Editor.app:"
end tell
tell application "Script Editor"
	display dialog "currentIndex1 = 1"
		--> {button returned:"OK"}
end tell
tell current application
	open for access file "Macintosh HD:Users:????:Library:Application Support:tweetIndex_xednIteewt.txt" with write permission
		--> 114
	set eof 114 to 0
	write 1 to 114 starting at eof as text
	close access 114
end tell

Result:
true

Yes I did get the same behaviour without editing the post and I ran with 5 pictures. I have just tried again as asked and the tweets stop on the last in the list. What I did try was deleting the last tweet from the twitter feed and running again. This then posted the last tweet again! Hop that helps?

I tried the syntax above, and it posted the tweets, but not the images.

Not sure if this will help, as you may already be aware of it, but the code below works if the images are hard coded, as in the example below:



set imagePath to "HARD Disk X:Users:USERNAME:Pictures:TweetImages:test.jpg" 
	
	tweet "Tweet testing" using account "MyTwitterAccount" with image imagePath 


Thanks

Did a bit of cleaning

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) samedi 8 juillet 2017 15:53:19

Hi Yvan,

It works on the first set of tweets, and cycles around once the list is complete, starting over as expected. However, it only posts the same tweet (tweet 21) of the second list of tweets! Both sets post with images, whether in the Pictures folder or a subfolder of the pictures folder, which it wasn’t doing earlier in the day when I tested, but is since coming back to post this message.

I know you are at the end of you tether with this but, I would be grateful if you could look at why the second list of tweets are not incrementing beyond the first message (tweet 21) in the list, as I can’t spot anything myself.

Also, would there be an easy way at the start of the code to enable / disable the accounts? For example use account 1 and 2 or use only account one or account two depending on what is set?

Did a bit of cleaning

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) dimanche 9 juillet 2017 10:24:58

Did a bit of cleaning

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) dimanche 9 juillet 2017 11:42:46

Hello Yvan,

I have tried the code using option 1 and 2 when presented, and get the error message below. I have not been able to confirm if the second set of messages increment, as nothing posts currently.

Please forgive me, I was not clear in my request for the ability to enable / disable account use. I was after a hard coded option for enabling, or disabling an account, and not anything requiring human interaction or button selections. :slight_smile:

Perhaps something at the start of the code, like the (rough) example below, which you provided in a different form for another script?


property howMany : 1

# 0 = disable all tweeting - Nothing will be posted. Use for safety when code is not intended to run
# 1 = use tweeterAccount, tweeterAccount2 - Default setting. This will use both defined accounts
# 2 = use tweeterAccount - Use only first account defined in the list of available accounts
# 3 = use tweeterAccount2 - Use only the Second account defined in the list of available accounts
-- If more than three accounts are defined in the system this code will ensure only those required, and defined, are accessed and used via the script.

Thank you.

Did a bit of cleaning

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) dimanche 9 juillet 2017 21:29:31

Hello Yvan,

On reflection I think I am trying to make the code far more complex than needed, as I believe I could simply remark out the second account tweet line, if it is not needed, or used.

As the code was working, minus the issue of not posting the second line of tweets beyond the first entry, could we revert to a simpler version that I can test each tweet account with to ensure the lists post, with an image?

Thank you.

Did you tested the late version posted in message #17?
It’s supposed to do the job flawlessly.

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) lundi 10 juillet 2017 10:48:56

Hello Yvan,

I did. But I may not have used the correct version, as it failed!

Could you link me to the version you want me to test and I will try it this evening, and post the results?

Did a bit of cleaning

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) lundi 10 juillet 2017 12:16:42

Hello Yvan,

I have tried several attempts to make the code run, and the following message box appears when running the latest code:

I know you don’t have access to twitter or use twitter, so I ran some local tests, which I hope help. Please forgive me if I am teaching you what you already know. :slight_smile:

The following code tells me I have three accounts setup:


tell application "Twitter Scripter"
	-- returns a list of usernames for the OS defined Twitter accounts
	set availableAccounts to available accounts
end tell

-- Result Screen: {"Hal","Batman", "Asterix"}

The above response for the returned list shows there are three accounts, all are active. Account names have been renamed for privacy.

Running the following command and replacing the ‘item’ number in each run, shows me which account a tweet will be posted from, based on the ‘Item’ number ‘set’ :



tell application "Twitter Scripter"
	

	-----------------------------------------
	-- Account commands
	-----------------------------------------
	
	-- returns a list of usernames for the OS defined Twitter accounts
	
	set availableAccounts to available accounts
	
	-- Test to check we've got at least one account
	
	if ((count of availableAccounts) is 0) then
		
		tell application "Finder"
			activate
			display dialog "Please set up at least one Twitter account in your System Preferences, and allow it to be accessed by \"Twitter Scripter\"" buttons {"OK"} default button "OK" with icon 2 with title "No Available Twitter Accounts"
		end tell
		return
	end if

#set twitterAccount to item 1 of availableAccounts -- uses account named Hal (default for live Tweets)
#set twitterAccount2 to item 2 of availableAccounts -- uses account named Batman (secondary account for live tweets)
set twitterAccount2 to item 3 of availableAccounts -- uses account named Asterix (default for testing and not used for live tweets)

#Replacing the item number with either 1, 2 or 3, as shown above, confirms in the result screen which account the number relates to. Below is the output per number  

# 1 = Hal returned from code when 'item' was set to 1
# 2 = Batman returned from code when 'item' was set to 2
# 3 = Asterix (item 3 is our test account) returned from code when 'item' was set to 3

end tell
return twitterAccount

-- Result Screen: "Asterix"

# depending on the item number above the output screen shows the account selected. In this instance 3 is set, which is our test account


Now using this command we set the account to use for tweeting:



set twitterAccount to item 3 of availableAccounts -- NOTE: set 'item' 3 which is the account [Asterix] for testing.
#Account three will be used for twitterAccount during tests, and also for testing twitterAccount2 when the primary twitterAccount is disabled.  


This then wraps into the following commands for a simple text based tweet test, which works well with the ‘set’ twitterAccount. Typically we are testing one account setup at a time to avoid posting to live accounts!


tweet "I'm tweeting from my desktop!" using account twitterAccount
#OR
tweet 'This is the second account for tweets!" using account twitterAccount2 

-- remember to change the 'item' number for each account. In our case we always use 3 for tests!

# I have removed image tweeting from the code for now to make life easier.

What I can’t see in your new code is where to ‘set’ the twitter account to use via twitter scripter. Please forgive me if it’s in the code, I just cant spot where to set this, and or what code to use.

Thank you.

Did a bit of cleaning

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) lundi 10 juillet 2017 18:22:36

Hello Yvan,

I have inserted comments commencing with – to your questions below. I am sorry for any confusion I am causing, and I am grateful for your amazing patience with me. :slight_smile:

The requirement below, in my mind is the same as above. However, it seems that the ‘item’ is what defines the account to use, so being able to quickly set this is essential.

I have made a small adjustment to the list below, which might clarify matters.

Did a bit of cleaning

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) lundi 10 juillet 2017 19:09:16

The real life configuration would be 2 for Index1 and 3 for Index2

However, the ability to change the item number associated with the index would be essential. Could this be achieved by simply editing the code, and changing the item number(s) as required?

Did a bit of cleaning

Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) lundi 10 juillet 2017 20:51:47

Hi Yvan,

When I change the settings in the code below to any value the result is constantly the same! Is that meant to happen? I was expecting the accounts shown in the result window to change.

The code below when run gave the output under result. The result changed if I changed the values up to the value 9, upon which it presented a coded message, as intended, requesting an account be set.

– Result: {“account2”, “account3”}