I get my teaching schedule and term plans in word doc table. I would like to know if there is a way to get this data into iCal. It will take me much longer to create events in iCal than what it would to copy these tables into an excel file and import to iCal from there.
The data would be one day events ie House-Gala Friday 22/02/2013 and the rest of the data will be 2 weeks or 3 weeks events ie 3 Weeks - Gr.10 Maths - Topic:Exponents (these events will be a 5 day event (Monday to Friday) repeated for three weeks.)
This is a script I got from the internet - but the first error it gives is me is that it can't convert the .csv file text into type Unicode.
Another issue later in the script will be to get those 5 day events to repeat for 3 or 2 weeks.
Any help would be greatly appreciated. This is what I have thus far:
--Convert CSV file to iCal events
--Prompts for file, then processes
--expects date,start time,end time,event name,xxxx,calendar name
--eg 12/01/2006,20:30,22:00,Water Committee,,TestCal
--change the various text item ns if data order in a file line is different
--blank lines skipped
--if other data present (eg location, notes ...) add a line in the tell calendar Calno loop
--to include it eg set location to text item 5 of ThisLine
set OldDelimiters to AppleScript's text item delimiters
set LF to ASCII character 10
set theFile to choose file with prompt "Select CSV calendar file"
set theLines to read theFile
set AppleScript's text item delimiters to {LF}
set theLines to paragraphs of theLines
set AppleScript's text item delimiters to {","}
repeat with ThisLine in theLines
if (count of ThisLine) > 0 then --ignore blanks
set StartDate to date (text item 1 of ThisLine & " " & text item 2 of ThisLine)
set EndDate to date (text item 1 of ThisLine & " " & text item 3 of ThisLine)
set CalName to word 1 of text item 6 of ThisLine
tell application "Calendar"
set CalList to title of every calendar
if CalName is in CalList then
repeat with CalNo from 1 to count of CalList
if CalName is item CalNo of CalList then exit repeat
end repeat
else
set NewOne to make new calendar at end of calendars with properties {title:CalName}
set CalNo to 1 + (count of CalList)
end if
tell calendar CalNo
set newItem to make new event at end of events with properties {start date:StartDate}
set summary of newItem to text item 4 of ThisLine
set end date of newItem to EndDate
end tell --calendar
end tell --iCal
end if
end repeat
set AppleScript's text item delimiters to OldDelimiters
Ok thanks for the replies, this is what I have thus far, I can't get the recurrence to use NumberCount as the COUNT for the repeat of the event:
set text item delimiters to ";"
repeat with l in paragraphs of (read "/Users/pienaar0/Desktop/test.csv" as «class utf8»)
if contents of l is not "" then
set sd to date (text item 1 of l & " ")
set ed to date (text item 2 of l & " ")
set NumberWeeks to (text item 4 of l & " ")
set NumberCount to NumberWeeks - 1
tell application "Calendar" to tell calendar "Test"
make new event with properties {allday event:true, start date:sd, end date:ed, summary:text item 3 of l, recurrence:"FREQ=WEEKLY;COUNT=2 * NumberCount"}
end tell
end if
end repeat
set text item delimiters to ","
repeat with l in paragraphs of (read "/Users/username/Desktop/test.csv" as «class utf8»)
if contents of l is not "" then
set sd to date (text item 1 of l & " " & text item 2 of l)
set ed to date (text item 1 of l & " " & text item 2 of l)
tell application "Calendar" to tell calendar "Test"
make new event with properties {start date:sd, end date:ed, summary:text item 4 of l}
end tell
end if
end repeat
test.csv:
01/25/2013,10:30PM,11:00PM,test event
01/26/2013,00:00AM,01:00AM,test event2
Related
I'm using the following code in Applescript to generate iTunes playlists from a tab-separated .txt file. However, I wondered if there is a way of getting it to check if the files are already in the target playlist before adding each file?
set thisTSVFile to (choose file with prompt "Select the CSV file")
readTabSeparatedValuesFile(thisTSVFile)
set theList to readTabSeparatedValuesFile(thisTSVFile)
tell application "iTunes"
set myPlaylist to playlist "InSLtxtLists"
set sourcePlaylist to playlist "Music"
end tell
repeat with i from 2 to number of items in readTabSeparatedValuesFile(thisTSVFile)
--gets first column
set theName to item 1 of item i of theList
--gets second
set theArtist to item 2 of item i of theList
tell application "iTunes"
try
duplicate (some track of sourcePlaylist whose name is theName and artist is theArtist) to myPlaylist
on error the errorMessage
set
end try
end tell
delay 0.1
end repeat
on readTabSeparatedValuesFile(thisTSVFile)
try
set dataBlob to (every paragraph of (read thisTSVFile))
set the tableData to {}
set AppleScript's text item delimiters to tab
repeat with i from 1 to the count of dataBlob
set the end of the tableData to (every text item of (item i of dataBlob))
end repeat
set AppleScript's text item delimiters to ""
return tableData
on error errorMessage number errorNumber
set AppleScript's text item delimiters to ""
error errorMessage number errorNumber
end try
end readTabSeparatedValuesFile
For reference, each line in the .txt file is formatted like this:
'Allo 'Allo! Theme (David Croft & Roy Moore) Jack Emblow 1982
I have two fields for current version number and previous version number in a form. What I want to do is when I enter the current version number (which is written like this 18.04.15), the previous version number on the next text box to automatically fill itself with 18.04.14.
I tried:
=[txtCurrentVersion]-1 in the control source, but obviously because I'm not decrementing by one, it didn't work.
Would appreciate some guidance, thanks :)
Below code splits the text based on dot and subracts one from last item.
Private Sub txtCurrentVersion_AfterUpdate()
If Nz(Me.txtCurrentVersion, "") <> "" Then
Me.txtPrevVersion.Value = Split(Me.txtCurrentVersion, ".")(0) & "." & Split(Me.txtCurrentVersion, ".")(1) & "." & Split(Me.txtCurrentVersion, ".")(2) - 1
End If
End Sub
I would suggest creating a function where you give the function 3 parameters, the 1st is the current version number string, the 2nd is the version number level (0 for major number, 1 for subversion number and 2 for minor version number) and the value to increase or decrease.
for example:
Function ModifyVersion(VersionNumber, NumberLevel, Number)
If VersionNumber <> "" AND NumberLevel >= 0 AND NumberLevel < 3 Then
dim VersionArray
VersionArray = Split(VersionNumber, ".")
Select Case NumberLevel
Case 0
VersionArray(0) = VersionArray(0) + Number
Case 1
VersionArray(1) = VersionArray(1) + Number
Case 2
VersionArray(2) = VersionArray(2) + Number
End Select
ModifyVersion = VersionArray(0) & "." & VersionArray(1) & "." & VersionArray(2)
End If
End Function
Then to decrease one from the minor version number use:
VersionNumber = [txtCurrentVersion]
Dim UpdateVersion
UpdateVersion = ModifyVersion(VersionNumber, 2, -1)
Generally people use the default option that Spotfire gives. Connect to the DB and pull the set of columns that you need and create an Information Link and load the data to Spotfire.
However, I am using SQL Query to fetch data to Spotfire. I am creating a table similar to Views, and writing a simple stored procedure to pull the data:
Create procedure ProcA(In Start_Date date, IN End_Date date, In Site_Name text)
Begin
SELECT * FROM TableA where day between Start_Date and End_Date and
site_name = Site_Name;
This works fine if I am not using site name filtering.
The Information Links helps in filtering the date properly. But when it comes to Site Name, nothing works.
There are 2 requirements:
Is it possible to give a drop-down just like how filter comes for Date
How to pass multiple site names to pull only those sites into the Spotfire file
TL;DR: There are better ways to do this; if it's just for the column names, I don't think it's worth it to do part 2, since it's easy enough to change the sql in the information link, but it's possible.
Okay, I will try (read: fail) not to be too long-winded.
1) Is it possible to do a drop-down for dates? Yes. The easiest way to do this would be to pull a data table with all of your date choices available for the end user. Here's an example finding a list of better way to generate months/year table Remember when creating your dropdownlist that your Document Property has to have the Data type "Date", and then you should be able to set property values through Unique Values in column against your date column from the new data, the same as you would do for a string drop-down list.
If you have a small subset of specific dates to choose from, this probably isn't too bad. If the drop down list gets longer, your end-users can type in the date they're looking for to speed up their search (though in my experience, a lot of them will scroll through until they find the date they're looking for).
While this is perfectly acceptable, if you're at all comfortable adding javascript, I'd personally recommend using a Popup Calendar These are fairly straightforward for end-users, and can allow them to use the calendar or type it themselves. (And if they type something that isn't a date in, it's even kind enough to inform them with red letters and an exclamation mark that they haven't typed an actual date)
2) How to pass multiple site names to pull only those sites into the Spotfire file
Hoo boi, where to start.
Step one: How do you want to select your list of Site Names? I'm going to go ahead and assume you have a data table with a list of distinct Site Names.
Your next choice is how to let your user select which Site Names they want. General options are using a List Box Filter, displaying a table and using marked rows, or providing a text area where the user can type their selections themselves.
When I needed to do this, I did a combo of a data table and a text area, so that's what I'm going to describe here.
I start off by providing the user with a text area, formatted to "specific size" with a larger than usual height to prompt that, yes, they are allowed to type multiple rows. If they know the values they're looking for, they can type them in manually, or copy paste from an excel file, etc.
If they don't know what they're looking for, the list of Site Names would be in a Table displayed for the user, where they can then mark the rows they want on the visualization and push a button which will do a cursor through the list of marked Site Names, concatenate them together, and put them in the text box previously mentioned (Note: if you don't want to let them enter their list manually, you can leave off the text area, combine these next two pieces of code, and throw it straight into the SpecialFilterProperty).
Please note that cursors are slow; if you have more than a few thousand rows to cycle through, this may stall out for a few seconds.
Code for the button:
from Spotfire.Dxp.Application.Visuals import CrossTablePlot
from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import RowSelection
from Spotfire.Dxp.Data import DataValueCursor
from Spotfire.Dxp.Data import DataSelection
TextFltr = ""
crossSource = Document.Data.Tables["Distinct_SiteNames"]
##Get a Row Count
rowCount = Document.Data.Tables["Distinct_SiteNames"].RowCount
##Index Set of all our rows
rowIndexSet=Document.ActiveMarkingSelectionReference.GetSelection(Document.Data.Tables["Distinct_SiteNames"]).AsIndexSet()
allRows = IndexSet(rowCount,True)
if rowIndexSet.IsEmpty != True:
allRows = rowIndexSet
colCurs = DataValueCursor.CreateFormatted(crossSource.Columns["Site_Name"])
##Optional: Loop through to determine average value
colTotal = ''
for row in crossSource.GetRows(allRows, colCurs):
colTotal += ', ' + colCurs.CurrentValue
if TextFltr == "":
TextFltr += colTotal[2:]
else:
TextFltr += colTotal
Document.Properties["SelectedSiteNames"] = TextFltr
from System.Collections.Generic import Dictionary
from Spotfire.Dxp.Application.Scripting import ScriptDefinition
import clr
scriptDef = clr.Reference[ScriptDefinition]()
Document.ScriptManager.TryGetScript("Change Special Filter Value", scriptDef)
params = Dictionary[str, object]()
Document.ScriptManager.ExecuteScript(scriptDef.ScriptCode, params)
At the bottom it references a second script; this is the script attached to the button that parses through the text area when the user wants to submit their selections and refresh the data table.
The General Code I've used is here, script titled "Change Special Filter Value", which allows delimiting by newline, tabs, commas, quotes, and a few others. Feel free to add or subtract here, depending on your user-base's needs.
strVals = Document.Properties["SelectedSiteNames"]
lst = ""
cnt = 0
x = 0
y = 0
z = 0
for letter in strVals:
if y == 1:
if letter == " ":
lst = lst + "'" + strVals[x:z] + "', "
y = 0
elif letter == ",":
lst = lst + "'" + strVals[x:z] + "', "
y = 0
elif letter == "\n":
lst = lst + "'" + strVals[x:z] + "', "
y = 0
elif letter == "\r":
lst = lst + "'" + strVals[x:z] + "', "
y = 0
elif letter == "'":
lst = lst + "'" + strVals[x:z] + "', "
y = 0
elif letter == '"':
lst = lst + "'" + strVals[x:z] + "', "
y = 0
elif letter == '\t':
lst = lst + "'" + strVals[x:z] + "', "
y = 0
else:
if letter <> " " and letter <> "," and letter <> "\n" and letter <> "\r" and letter <> "'" and letter <> '"' and letter <> "\t":
if y == 0:
cnt += 1
print letter
x = z
y = 1
z += 1
if y == 1:
lst = lst + "'" + strVals[x:z] + "', "
print lst
lst = lst.upper()
if len(lst) > 0:
lst = lst[1:len(lst) - 3]
Document.Properties["SpecialFilterValue"] = lst
Step one is now complete! You have a list of all your selected site names in a property that you can now pass to your stored procedure.
Note: I believe there's a limit to the number of characters Spotfire can pass through a string value. In my previous testing, I think it's been over 500,000 characters (it's been a while, so I don't remember exactly), so you have a lot of leeway, but it does exist, and depending on which data source you're using, it may be lower.
Step Two: Alter the stored Procedure
Your stored procedure will basically be something along the lines of this:
Create procedure ProcA(In Start_Date date, IN End_Date date, In Site_Name text)
Begin
DECLARE #Script nvarchar(max) =
N'
Select * from TableA where day between Start_Date and End_Date and Site_Name in (' + #Site_Name + ') '
EXECUTE (#Script)
Downright easy in comparison!
(No loop after all! The bizarre use case I was remembering doesn't apply here, unless you're also using a data base that doesn't allow you to pass parameters directly...)
Goal: Long list of purchase orders that I need to refund if they contain the word "From:" and each purchase has a order number and I have been trying to parse or loop, not sure of right word Search HTML doc for instance of the word "From:" and if found, then get other number and print to a text file.
So far, I was able to learn, sort of how to use text item delimiters, but when I tried making it loop or repeat, I just got the same order number over and over. This is before even trying to implement the part that says IF order details include word "from" then get order number.
set astid to AppleScript's text item delimiters
set x to 2
set startHere to "p class=\"webOrderNumber\">"
set stopHere to "</p>"
set entireText to (do shell script "curl file:///Users/Michael/Desktop/StorePurchases.webarchive")
set AppleScript's text item delimiters to startHere
set blurb1 to text item x of entireText
repeat with i from 2 to (count of blurb1)
set thisItem to item i of blurb1
set AppleScript's text item delimiters to stopHere
set blurb2 to text item 1 of blurb1
set AppleScript's text item delimiters to astid
set writeFile to ((path to desktop as text) & "test_output") --
set writeData to blurb2
set success to appendDataToFile(writeData, writeFile)
end repeat
on appendDataToFile(myData, aFile)
set OA to (open for access aFile with write permission)
try
write (myData & (ASCII character 10)) as text to OA starting at eof
close access OA
return true
on error
try
close access OA
end try
return false
end try
end appendDataToFile
Here is an excerpt of the HTML:
</td>
<td class="OrderNumber">
<p class="webNumber">BHWL123456</p>
</p>
<td class="OrderNumber">
<p class="details">
Full Version: Get all Activities & Remove ads! [From: Pony Resort: MakeverMagic] </p>
</td>
This is going to be used when there are hundreds of orders that would take too long to physically search for the word FROM and write the order number.
Try:
set resultNumbers to {}
set myText to read file ((path to temporary items as text) & "test.txt") as «class utf8»
set {TID, text item delimiters} to {text item delimiters, "<p class=\"webNumber\">"}
set webOrderNumbers to text items 2 thru -1 of myText
set AppleScript's text item delimiters to "</p>"
repeat with wNumber in webOrderNumbers
set end of resultNumbers to text item 1 of wNumber
end repeat
set text item delimiters to TID
return resultNumbers
This question was asked and solved afaik on Macscripter.net with the use of a Applescript Script library and additional Applescript I provided in this thread.
The scripting library uses NSRegularExpresion to search between two text targets and return all occurrences in one go.
I can post the code here if anyone is interested or you can visit the thread.
I am working with an Access database where I have a form that contains several date entry fields. I have a new user that is used to using a period as a delimiter for dates so instead of "6/22/11" or "6-22-11", they enter "6.22.11". I would like to continue to allow this type of entry, but Access converts "6.22.11" to a time instead of a date. I have tried setting the format on the text box to "Short Date" with no help. I have also tried adding code to the "Lost Focus" event but that is to late since Access has already done the conversion. The "Before Update" event fires before the conversion but will not allow me to change the text in the textbox. Any ideas on how I can allow all three forms of date entry?
your above example
Private Sub Texto0_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = "." Then
KeyAscii = Asc("/")
End If
End Sub
works for me.
Another aproximation is play with the BeforeUpdate and AfterUpdate events.
In BeforeUpdate you cannot modify de content of the control, but you can set a flag (a variable defined at module/form level) in the AfterUpdate event and change the content: it will trigger again the BeforeUpdate, but in this case, because is flagged you sould ignore it and unflag.
http://office.microsoft.com/en-us/access-help/control-data-entry-formats-with-input-masks-HA010096452.aspx
Input Mask.
I wrote the following function for a user who was used to entering 6 and 8 digit dates in input masks by just typing a string of numbers with no delimiter. You should be able to modify it for your purposes:
'---------------------------------------------------------------------------
' Purpose : Enables entry of 8-digit dates with no delimiters: 12312008
' Usage : Set OnChange: =DateCtlChange([Form].[ActiveControl])
' 8/ 6/09 : Allow entry of 6-digit dates with no delimiters
' (year 2019 and 2020 must still be entered as 8-digit dates)
'---------------------------------------------------------------------------
Function DateCtlChange(DateCtl As TextBox)
Dim s As String, NewS As String
On Error GoTo Err_DateCtlChange
s = DateCtl.Text
Select Case Len(s)
Case 6
If s Like "######" Then
If Right(s, 2) <> "19" And Right(s, 2) <> "20" Then
NewS = Left(s, 2) & "/" & Mid(s, 3, 2) & "/" & Mid(s, 5, 2)
End If
End If
Case 8
If s Like "########" Then
NewS = Left(s, 2) & "/" & Mid(s, 3, 2) & "/" & Mid(s, 5, 4)
End If
End Select
If IsDate(NewS) Then
DateCtl.Text = NewS
DateCtl.SelStart = Len(DateCtl.Text)
End If
Exit_DateCtlChange:
Exit Function
Err_DateCtlChange:
Select Case Err.Number
'Error 2101 is raised when we try to set the text to a date
' that fails the date control's validation
Case 2101 'The setting you entered isn't valid for this property.
'Log error but don't show user
Case Else
'Add your custom error logging here
End Select
Resume Exit_DateCtlChange
End Function
Access uses the system date and time format to determine how to translate a value. Another option - that would affect every program on this user's computer - is this: http://office.microsoft.com/en-us/access-help/change-the-default-date-time-number-or-measurement-format-HA010351415.aspx?CTT=1#BM2
Alternatively you can use spaces instead of slashes in dates in Access. Thus the user can use the left hand on the space bar and use the right hand on the numeric keyboard. I feel this is much easier to use than either the slash or the hyphen.