Saturday, September 23, 2017

#1 2017-07-05 05:47:15 pm

Prescience
Member
From:: United Kingdom
Registered: 2017-02-03
Posts: 43

Help Completing / Coding Droplet for Tweeting via Twitter Scripter

Hello,

I have zero coding skill, but thanks to help in the past have constructed an outline of code, which is intended to help with what I would like to achieve, uses some base code that works, and other parts that need someone with real coding skills to complete, and add the missing sauce.

Using Twitter Scripter I have been able to successfully tweet, and also tweet with an image!  This led to the idea of using a droplet to drop images onto when on location which would automatically tweet to an account or accounts, which we have setup on our MacMini for the image placed in the specified folder.

Expanding this further, we had the idea of using multiple accounts from the team to maximise coverage using the same image, but with different tweets for the account used.

I do not know how to setup the code below to work.  This includes the way to attach the account defined to work with Twitter with the related tweets, how to enable or disable the droplet, how to setup to run with one, two or all accounts, and how to set the image path to not require the name of the image to work, as it should only run with the image dropped onto the application.

In addition, I would like to send an iMessage once the tweet(s) have been sent. This could simply state that a tweet has been sent, but would be great if it could include the actual tweet from the account or accounts used. 


Below is the code I have created so far with comments around the missing elements or parts that I have not been able to complete!

Thank you all in advance. smile



# Tweets will post the same image associated with this script, and then post to the account specified with the tweet(s) allocated to the associated account.

# Is it possible to check if Twitter is alive first?  This is not essential but a nice to have. No code added, as don't know where to start on this!
# This scrip will be using Twitter Scripter, which works with the Twitter Accounts defined in the Mail, Contacts & Calendars System Preference in Mac OS 10.8
# http://mousedown.net/mouseware/TwitterScripter.html for more details and download of current version from Mousedown
# http://mousedown.net/mouseware/TwitterS … mples.html for examples


property enableTwitter : true
# true  use twitter
# false  disable using twitter
-- I would like the ability to enable of disable use of the code. Don't know what to add for this to work!

property enableAccounts : 0
# 0 = use the primary account only
# 1 = use for primary and secondary account
# 2 = use for enabling all three accounts
-- No idea how to code the above into the rest of the script!

property myTwitterAccount1 : "<AccountOne>" # used for primary Twitter account. This is the account name setup in the system e.g. @FredBlogs
property myTwitterAccount2 : "<AccountTwo>" # used for second Twitter account
property myTwitterAccount3 : "<AccountThree>" # used for third Twitter account
-- Each Twitter account must be enabled to work! If not enabled no tweets for the disabled account will be sent!

property theHashTags : {"#Tag1, #Tag2"}
-- These will be added to every post and account where included. Used for Twitter walls where a key tag is required

-- Need a way to enable or disable multiple Twitter accounts. Default is Primary account if enabled. Second and Third account will fail gracefully if turned on with no tweets. For example no error message and the script continues processing.

property theTweetsAccount1 : {"Tweet 1", "Tweets 2", "Tweet 3", "Tweet 4"}
-- Edit it to fit needs for Twitter Account 1. Each tweet will appear sequentially until reaching the end, and will then start from Tweet 1

property currentTweetsIndex1 : 1
-- Associated to Twitter Account 1

property theTweetsAccount2 : {"Tweet 1", "Tweets 2", "Tweet 3", "Tweet 4"}
-- Edit it to fit needs for Twitter Account 2. Each tweet will appear sequentially until reaching the end, and will then start from Tweet 1

property currentTweetsIndex2 : 1
-- Associated to Twitter Account 2

property theTweetsAccount3 : {"Tweet 1", "Tweets 2", "Tweet 3", "Tweet 4"}
-- Edit it to fit needs for Twitter Account 3. Each tweet will appear sequentially until reaching the end, and will then start from Tweet 1

property currentTweetsIndex3 : 1
-- Associated to Twitter Account 3

# END Tweeting setup

# Tweeting from here   

# Tweet sending a picture. Note that for security pictures must be sourced from within the Pictures folder in your home folder

tell application "Twitter Scripter"
   
    -- The following code needs to send the same image to each enabled Twitter account, and use the tweets associated with each account if enabled, or only the primary account if only one account is setup.
   
    set imagePath to "HARD Disk X:Users:USERNAME:Pictures:TweetImages:test.jpg" # needs to work with any image dropped onto the application
   
    -- Have not been able to make the code work with an image unless the full name is specified i.e. Test.jpg! 
   
    tweet "Tweet testing" using account "MyTwitterAccount1" with image imagePath #Default account if Tweets are enabled
   
    tell me to delay 20
   
    tweet "Tweet from theTweets2 & TheHasTag" using account "MyTwitterAccount2" with image imagePath # Second account if enabled
   
    tell me to delay 30
   
    tweet "Tweet from theTweets3 & TheHasTag" using account "MyTwitterAccount3" with image imagePath # Third account tweets if enabled
   
end tell

tell me to delay 20 # used before sending an iMessage to confirm tweet sent


# iMessage notifications

-- Code here to send an iMessage with tweet details  associated with the enabled account or accounts

# Tweet Code ends here


Wisdom is knowing the power of experience, understanding the knowledge learnt on your personal journey through time, and having the empathy to share with others.

Offline

 

#2 2017-07-06 12:34:22 pm

kerflooey
Member
Registered: 2011-07-07
Posts: 134

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

Hi. What OS version are you using to send a tweet successfully? I'm trying with Sierra but having no success. Thanks.

Offline

 

#3 2017-07-06 12:43:44 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3194

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

In the original question we may read :

# This scrip will be using Twitter Scripter, which works with the Twitter Accounts defined in the Mail, Contacts & Calendars System Preference in Mac OS 10.8


Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) jeudi 6 juillet 2017 19:43:39

Offline

 

#4 2017-07-06 01:05:43 pm

kerflooey
Member
Registered: 2011-07-07
Posts: 134

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

Thanks. Just downloaded the new version 1.03 which allows it to run successfully in Sierra.

Offline

 

#5 2017-07-06 01:48:23 pm

Prescience
Member
From:: United Kingdom
Registered: 2017-02-03
Posts: 43

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

Sierra with the latest version. Glad you've got it running now.

Hoping someone can help me with my script request. smile


Wisdom is knowing the power of experience, understanding the knowledge learnt on your personal journey through time, and having the empathy to share with others.

Offline

 

#6 2017-07-06 03:52:28 pm

kerflooey
Member
Registered: 2011-07-07
Posts: 134

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

This doesn't answer all of your questions, but I tested this quick & dirty script successfully. It just tweets three texts with a pic each.

Applescript:


set theText to {"Uno", "Dos", "Tres"}
set thePicNames to {"1.jpg", "2.jpg", "3.jpg"}
set thePicPath to (path to pictures folder) as text
set thePix to {}
repeat with aPicName in thePicNames
   set thePix to thePix & (thePicPath & (aPicName as text))
end repeat

set picNum to 0

tell application "Twitter Scripter"
   repeat with aTweet in theText
       set picNum to (picNum + 1)
       tweet (aTweet as text) using account "twitteracctname" with image (item picNum of thePix)
   end repeat
end tell

Offline

 

#7 2017-07-07 03:05:02 am

Prescience
Member
From:: United Kingdom
Registered: 2017-02-03
Posts: 43

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

Thanks Kerflooey.

Just run the code you kindly provided, and it worked on the first image, posted the second image as text only, and didn't post the third tweet at all.

There are two issues I see with this, the first being we don't know the name of the image we are posting, and if we take the time to create an image name and add it, we might as well post manually.

Secondly, it seems to post all tweet items at once, and not sequentially, which is our aim. The plan being we drop an image on the droplet, it takes a tweet from the list created, posts it with the tweet 'Uno' in your example, and the next image dropped is posted with the tweet 'Dos' and so on until the list of tweets is exhausted. At this point the tweets would start from the beginning i.e. 'Uno', and then cycle through the list again!

Ideally we would then like the script to do the same with a second set of tweets assigned to a second account.


Hoping you or someone can help further. smile


Wisdom is knowing the power of experience, understanding the knowledge learnt on your personal journey through time, and having the empathy to share with others.

Offline

 

#8 2017-07-07 04:08:44 pm

Prescience
Member
From:: United Kingdom
Registered: 2017-02-03
Posts: 43

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

Hi Guys,

I have made some small progress with the following code. I would appreciate some assistance in building on the code to run sequentially tweets from the defined tweets in 'theTweets' list, and to include images dropped onto the app from within a subfolder of the picture folder, when tweeting.  Image have to be in this location for security purposes, according to Twitter Scripter.

The code provided kindly by Kerflooey worked with hard coded image names, although the tweets failed. I hope I can add images to  tweets from the safe folder location by dropping them on the droplet, and therefor not requiring the image name to be hard coded in a similar fashion to the code Yvan created for us to use for emails.

Hopefully, someone can assist with the missing code elements, as we seem to be on the right path.

Please note. I am the worst kind of coder, as I am not a coder at all!

Thank you all in advance.

Applescript:




tell application "Twitter Scripter"
   
   # First account in available list = Name
   # Second account in available list = Primary Name
   # Note the first account may not be the default account! Naming appears to be alphabetical when results are returned
   
   -----------------------------------------
   -- 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 2 of availableAccounts -- choose the second (primary) available account
   
end tell

#set theText to {"Uno", "Dos", "Tweet 3", "Tweet 4"} # This approach posts ALL tweets at once if there is no associated image to match the tweets!

property theTweets : {"Testing Tweets from my desktop again", "#HappyDays more testing of desktop tweets", "Follow the tweeting challenge"} # This version posts a single tweet, however fails on second run

property currentIndex1 : 1 # Tweets for Account 2, which is our primary account!

#on open droppedFiles # droppedFiles is a list of aliases
#    new_tweet(droppedFiles)
#end open

-- Used to try and run the code when an image is opened with the droplet within a subfolder of the pictures folder


set theTweets to item currentIndex1 of theTweets

set currentIndex1 to currentIndex1 + 1
if currentIndex1 > (count theTweets) then set currentIndex1 to 1

#set thePicNames to {} # Removed for initial text based tweeting only as did not run, per my previous update

#set thePicPath to (path to pictures folder) as text #Subfolder in the Pictures folder will be used
#set thePix to {}
#repeat with aPicName in thePicNames
#set thePix to thePix & (thePicPath & (aPicName as text))
#end repeat

#set picNum to 0

tell application "Twitter Scripter"
   
   #repeat with aTweet in theText
   #set picNum to (picNum + 1)
   #tweet (aTweet as text) using account twitterAccount2 with image (item picNum of thePix)
   #end repeat
   
   #tweet (theTweets as text) using account twitterAccount2 with image (item picNum of thePix)
   
   tweet (theTweets as text) using account twitterAccount2
-- Tweet works but does not increment from theTweets list! Posts a random character when the code is run a second time, and then returns a failed result if run again!
   
end tell


Wisdom is knowing the power of experience, understanding the knowledge learnt on your personal journey through time, and having the empathy to share with others.

Offline

 

#9 2017-07-08 04:31:18 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3194

Re: 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 11:31:01

Last edited by Yvan Koenig (2017-07-12 09:08:04 am)

Offline

 

#10 2017-07-08 05:55:32 am

Prescience
Member
From:: United Kingdom
Registered: 2017-02-03
Posts: 43

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

Hello Yvan,

The code works with the following observations:

1 - theTweets list was used each time the code ran, with a new tweets for each time the code was used.  However, once all of the test tweets were used it did not start from the beginning to repost from tweet one again.  The code appeared to run, with no errors, but no new tweets were seen on the Twitter feed.

2 - When using the full version to include an image it did not post an image, but it did post the text tweet, and used a new tweet each time, with the same behaviour as above in point 1, once the test tweet limit was exceeded.

I note if the text in the tweets is adjusted a small amount the tweets post fine until the limit is reached.  I wonder if this is a limitation of twitter or twitter scripter, in terms of not re-posting the same text tweet more than once? On three separate tests the tweets did not repeat on the twitter feed once the last tweet in the list had been used, although the code appeared to run fine, with the exception of not posting the image in the full version.

Perhaps adding the name of the image minus the extension, would help if this is the case, as the image names will always increment.

This is most definitely helpful, and a step in the right direction - thanks you.


Wisdom is knowing the power of experience, understanding the knowledge learnt on your personal journey through time, and having the empathy to share with others.

Offline

 

#11 2017-07-08 07:33:06 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3194

Re: 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

Last edited by Yvan Koenig (2017-07-12 09:08:35 am)

Offline

 

#12 2017-07-08 08:21:07 am

Prescience
Member
From:: United Kingdom
Registered: 2017-02-03
Posts: 43

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

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.


Applescript:


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


Wisdom is knowing the power of experience, understanding the knowledge learnt on your personal journey through time, and having the empathy to share with others.


Filed under: tw

Offline

 

#13 2017-07-08 08:35:10 am

Prescience
Member
From:: United Kingdom
Registered: 2017-02-03
Posts: 43

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

Did you got this behavior without no editing task between two runs ?
I ask because when we edit a script, the properties are reset to the value written in the code.
Running the script with two dropped pictures set the property currentIndex1 to 3 but editing the script reset it to 1.
It's one of the reasons which explain why I dislike properties for this task.
To be sure, drop 5 pictures onto the droplet.


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?

In every examples which I found on the net, paths were passed as text objects.
Maybe they are wrong.

try to use the syntax :
Open this Scriplet in your Editor:
tweet theTweet using account anAccount with image aPicPath # this time we pass an alias


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:

Applescript:



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

Thanks


Wisdom is knowing the power of experience, understanding the knowledge learnt on your personal journey through time, and having the empathy to share with others.

Offline

 

#14 2017-07-08 08:57:06 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3194

Re: 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 15:53:19

Last edited by Yvan Koenig (2017-07-12 09:08:58 am)

Offline

 

#15 2017-07-08 03:11:48 pm

Prescience
Member
From:: United Kingdom
Registered: 2017-02-03
Posts: 43

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

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?


Wisdom is knowing the power of experience, understanding the knowledge learnt on your personal journey through time, and having the empathy to share with others.

Offline

 

#16 2017-07-09 03:48:24 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3194

Re: 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) dimanche 9 juillet 2017 10:24:58

Last edited by Yvan Koenig (2017-07-12 09:09:16 am)

Offline

 

#17 2017-07-09 04:44:53 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3194

Re: 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) dimanche 9 juillet 2017 11:42:46

Last edited by Yvan Koenig (2017-07-12 09:09:40 am)

Offline

 

#18 2017-07-09 12:09:14 pm

Prescience
Member
From:: United Kingdom
Registered: 2017-02-03
Posts: 43

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

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.

{item 1 of {alias "Macintosh HD:Users:?????:Pictures:TweetImages:Test-Picture.jpg"}, "TestAccount", false, 1, 1} doesn’t match the parameters {aPicPath, anAccount, otherAccount, currentIndex1, currentIndex2, howMany} for new_tweet. (-1721)


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. smile

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

Applescript:


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.


Wisdom is knowing the power of experience, understanding the knowledge learnt on your personal journey through time, and having the empathy to share with others.

Offline

 

#19 2017-07-09 02:32:04 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3194

Re: 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) dimanche 9 juillet 2017 21:29:31

Last edited by Yvan Koenig (2017-07-12 09:10:12 am)

Offline

 

#20 2017-07-09 06:31:03 pm

Prescience
Member
From:: United Kingdom
Registered: 2017-02-03
Posts: 43

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

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.


Wisdom is knowing the power of experience, understanding the knowledge learnt on your personal journey through time, and having the empathy to share with others.

Offline

 

#21 2017-07-10 03:49:04 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3194

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

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

Offline

 

#22 2017-07-10 04:53:37 am

Prescience
Member
From:: United Kingdom
Registered: 2017-02-03
Posts: 43

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

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?


Wisdom is knowing the power of experience, understanding the knowledge learnt on your personal journey through time, and having the empathy to share with others.

Offline

 

#23 2017-07-10 05:18:37 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3194

Re: 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) lundi 10 juillet 2017 12:16:42

Last edited by Yvan Koenig (2017-07-12 09:10:36 am)

Offline

 

#24 2017-07-10 10:44:26 am

Prescience
Member
From:: United Kingdom
Registered: 2017-02-03
Posts: 43

Re: Help Completing / Coding Droplet for Tweeting via Twitter Scripter

Hello Yvan,

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

Dialog box header: "Twitter Account's item is missing!"

Please set it up in your System Preferences, and allow it to be accessed by "Twitter Scripter"


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. smile

The following code tells me I have three accounts setup:

Applescript:


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' :

Applescript:



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:

Applescript:



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!

Applescript:


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.


Wisdom is knowing the power of experience, understanding the knowledge learnt on your personal journey through time, and having the empathy to share with others.

Offline

 

#25 2017-07-10 11:26:33 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3194

Re: 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) lundi 10 juillet 2017 18:22:36

Last edited by Yvan Koenig (2017-07-12 09:10:59 am)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)