Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. on daysInMonth for theDate -- returns an integer
  2.     copy theDate to d
  3.     set d's day to 32
  4.     32 - (d's day)
  5. end daysInMonth
  6. using terms from application "Colloquy"
  7.    
  8.     on process user command c with arguments for view
  9.        
  10.         if c is "itunes" then
  11.            
  12.             set itunes_active to false
  13.            
  14.             tell application "Finder"
  15.                 if (get name of every process) contains "iTunes" then
  16.                     set itunes_active to true
  17.                 end if
  18.             end tell
  19.            
  20.             if itunes_active then
  21.                 set itunes_message to do_itunes()
  22.                 tell view to send message itunes_message with action tense
  23.             end if
  24.             return true
  25.            
  26.         end if
  27.         return false
  28.        
  29.     end process user command
  30.    
  31. end using terms from
  32.  
  33. on do_itunes()
  34.    
  35.     set got_track to false
  36.    
  37.     tell application "iTunes"
  38.         if player state is playing then
  39.             set theTrack to name of the current track
  40.             set theArtist to artist of the current track
  41.             set playedCount to ((played count of the current track) + 1) as string
  42.             set playdate to date added of the current track
  43.             set got_track to true
  44.         end if
  45.     end tell
  46.     set today to current date
  47.    
  48.     -- we have the track info
  49.    
  50.     if got_track then
  51.        
  52.         -- create the contents of the message
  53.        
  54.         set monthdays to daysInMonth for (playdate)
  55.        
  56.         set dayshad to (day of today) - (day of playdate)
  57.         set monthshad to (month of today) - (month of playdate)
  58.        
  59.         if dayshad is less than 0 then
  60.             set monthshad to monthshad - 1
  61.             set dayshad to dayshad + monthdays
  62.         end if
  63.        
  64.         set yearshad to (year of today) - (year of playdate)
  65.        
  66.         if monthshad is less than 0 then
  67.             set yearshad to yearshad - 1
  68.             set monthshad to monthshad + 12
  69.         end if
  70.        
  71.         if yearshad is 0 then
  72.             set yearDis to ""
  73.         else
  74.             if yearshad is greater than 1 then
  75.                 set yearPlu to "s"
  76.             else
  77.                 set yearPlu to ""
  78.             end if
  79.             set yearDis to yearshad & " year" & yearPlu as text
  80.         end if
  81.        
  82.         if monthshad is 0 then
  83.             set monthDis to ""
  84.         else
  85.             if monthshad is greater than 1 then
  86.                 set monthPlu to "s"
  87.             else
  88.                 set monthPlu to ""
  89.             end if
  90.             set monthDis to monthshad & " month" & monthPlu as text
  91.         end if
  92.        
  93.         if dayshad is 0 then
  94.             set dayDis to ""
  95.         else
  96.             if dayshad is greater than 1 then
  97.                 set dayPlu to "s"
  98.             else
  99.                 set dayPlu to ""
  100.             end if
  101.             set dayDis to dayshad & " day" & dayPlu as text
  102.         end if
  103.        
  104.         if dayDis is not "" then
  105.             if monthDis is not "" or yearDis is not "" then
  106.                 set dayDis to " and " & dayDis
  107.             end if
  108.         end if
  109.        
  110.         if monthDis is not "" and yearDis is not "" then
  111.             if dayDis is "" then
  112.                 set monthDis to " and " & monthDis
  113.             else
  114.                 set monthDis to ", " & monthDis
  115.             end if
  116.         end if
  117.        
  118.         set weekTH to yearDis & monthDis & dayDis
  119.        
  120.         if weekTH is "" then
  121.             set weekTH to "few hours"
  122.         end if
  123.        
  124.         if length of playedCount is greater than 1 then
  125.             set tens to text ((length of playedCount) - 1) thru (length of playedCount) of playedCount
  126.             set tens to tens as number
  127.         else
  128.             set tens to playedCount as number
  129.         end if
  130.         if tens is greater than 10 and tens is less than 20 then
  131.             set timeTH to playedCount & "th"
  132.         else
  133.             if last character of playedCount is "1" then
  134.                 set timeTH to playedCount & "st"
  135.             else
  136.                 if last character of playedCount is "2" then
  137.                     set timeTH to playedCount & "nd"
  138.                 else
  139.                     if last character of playedCount is "3" then
  140.                         set timeTH to playedCount & "rd"
  141.                     else
  142.                         set timeTH to playedCount & "th"
  143.                     end if
  144.                 end if
  145.             end if
  146.         end if
  147.        
  148.         set the theContents to "is listening to \"" & theTrack & "\" by " & theArtist & " for the " & timeTH & " time in the " & weekTH & " that he's had the track."
  149.        
  150.         return theContents
  151.        
  152.     end if -- end of we have track info
  153. end do_itunes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement