When I run the following macro, I get this error:
The "join" property requires an object, instead found "undefined" from "$dayNames{?}"
I wonder if it's just me, or do other forum members also see this?
Code: Select all
### Insert Calendar ###
# Inserts a calendar showing the current month.
# Localized day names may not be correct.
# This macro was originally written by Kino, whose other macros can
# be found at http://www2.odn.ne.jp/alt-quinon/files/NWPro/
Require Pro Version 1.3
$lproj = Application Property 'localization'
$doc = Document.active
if $doc == undefined
exit
end
$origSel = $doc.textSelection
$origSel.length = 0
$dayNames = Hash.new
$dayNames{'Danish'} = Array.new 'ma', 'ti', 'on', 'to', 'fr', 'lø', 'sø'
#$dayNames{'English'} = Array.new 'Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat'
$dayNames{'English'} = Array.new 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat', 'Sun'
$dayNames{'French'} = Array.new 'dim','lun','mar','mer','jeu','ven','sam'
$dayNames{'German'} = Array.new 'Son','Mon','Die','Mit','Don','Fre','Sam'
$dayNames{'Italian'} = Array.new 'dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'
$dayNames{'Japanese'} = Array.new '日','月','火','水','木','金','土'
$dayNames{'Polish'} = Array.new 'Pn', 'Wt', 'Śr', 'Cz', 'Pt', 'So', 'N'
$dayNames{'Spanish'} = Array.new 'dom','lun','mar','mié','jue','vie','sm'
$dayNamesText = $dayNames{$lproj}.join "\t"
$SundayColor = Color.newWithRGB 0.498, 0, 0 # Dark Red
$SaturdayColor = Color.newWithRGB 0, 0, 0.498 # Dark Blue
$calData = undefined
begin Perl
$calData = `/usr/bin/cal`;
end
$calData.replaceAll '^\x20+|\n+\z', '', 'E'
$calData = $calData.split "\n"
foreach $i, $data in $calData
if $i == 0 # overwrite the 1st row (month, year)
$now = Date.now
$month = Date.nameOfMonth $now.month
$data = $month & "\x20"
$data &= $now.year
elsif $i == 1 # overwrite the 2nd row (day names)
$data = $dayNamesText
$data = $dayNames{$lproj}.join "\t"
else
$data.replaceAll '\x20+', '\t', 'E'
if $i == 2 # 3rd row: first week
$n = 13 - $data.length
$n = $n / 2
$leadingTab = undefined
while $n
$leadingTab &= "\t"
$n -= 1
end
$data = $leadingTab & $data
end
end
$calData[$i] = $data
end
$calData = $calData.join "\n"
$calData = $calData & "\n"
$calData = Cast to String $calData
$calData = Cast to Attributed String $calData
$SmallCaps = $Bold = $Italic = $Shadow = $ConvertToTable = $MergeCells = $AlignCellsCenter = $AlignCellsMiddle = Hash.new
$SmallCaps{'Danish'} = ':Format:STORT/lille tegn:Vis som små kapitæler'
$Bold{'Danish'} = ':Format:Fed'
$Italic{'Danish'} = ':Format:Kursiv'
$Shadow{'Danish'} = ':Format:Skygge'
$ConvertToTable{'Danish'} = ':Tabel:Konverter til tabel'
$MergeCells{'Danish'} = ':Tabel:Flet celler'
$AlignCellsCenter{'Danish'} = ':Tabel:Justér celler:Centreret'
$AlignCellsMiddle{'Danish'} = ':Tabel:Justér celler:Midte'
$SmallCaps{'English'} = ':Format:Character Case:Display as Small Caps'
$Bold{'English'} = ':Format:Font Face:Bold'
$Italic{'English'} = ':Format:Font Face:Italic'
$Shadow{'English'} = ':Format:Font Face:Shadow'
$ConvertToTable{'English'} = ':Table:Convert to Table'
$MergeCells{'English'} = ':Table:Merge Cells'
$AlignCellsCenter{'English'} = ':Table:Align Cells:Center'
$AlignCellsMiddle{'English'} = ':Table:Align Cells:Middle'
$SmallCaps{'French'} = ':Format:Casse Caractère:Afficher comme Petites Majuscules'
$Bold{'French'} = ':Format:Gras'
$Italic{'French'} = ':Format:Italique'
$Shadow{'French'} = ':Format:Ombre'
$ConvertToTable{'French'} = ':Tableau:Convertir en tableau'
$MergeCells{'French'} = ':Tableau:Fusionner les Cellules'
$AlignCellsCenter{'French'} = ':Tableau:Aligner les cellules:Centrer'
$AlignCellsMiddle{'French'} = ':Tableau:Aligner les cellules:Deuxième nom'
$SmallCaps{'German'} = ':Format:Groß-/Kleinschreibung:Anzeigen als Kapitälchen'
$Bold{'German'} = ':Format:Fett'
$Italic{'German'} = ':Format:Kursiv'
$Shadow{'German'} = ':Format:Schatten'
$ConvertToTable{'German'} = ':Tabelle:In Tabelle umwandeln'
$MergeCells{'German'} = ':Tabelle:Zellen zusammenführen'
$AlignCellsCenter{'German'} = ':Tabelle:Zellen ausrichten:Zentriert'
$AlignCellsMiddle{'German'} = ':Tabelle:Zellen ausrichten:Mitte'
$SmallCaps{'Italian'} = ':Formato:Maiuscole/minuscole:Mostra in maiuscoletto'
$Bold{'Italian'} = ':Formato:Neretto'
$Italic{'Italian'} = ':Formato:Corsivo'
$Shadow{'Italian'} = ':Formato:Ombreggiato'
$ConvertToTable{'Italian'} = ':Tabella:Converti in tabella'
$MergeCells{'Italian'} = ':Tabella:Unisci celle'
$AlignCellsCenter{'Italian'} = ':Tabella:Allinea celle:Centrato'
$AlignCellsMiddle{'Italian'} = ':Tabella:Allinea celle:Centro'
$SmallCaps{'Japanese'} = ':フォーマット:小文字/大文字:Small Caps'
$Bold{'Japanese'} = ':フォーマット:太字'
$Italic{'Japanese'} = ':フォーマット:斜体'
$Shadow{'Japanese'} = ':フォーマット:影付き'
$ConvertToTable{'Japanese'} = ':表:表に変換'
$MergeCells{'Japanese'} = ':表:セル結合'
$AlignCellsCenter{'Japanese'} = ':表:セル内位置揃え:中央揃え'
$AlignCellsMiddle{'Japanese'} = ':表:セル内位置揃え:中央'
$SmallCaps{'Polish'} = ':Format:Wielkość Znaków:Wyświetl jakokapitaliki'
$Bold{'Polish'} = ':Format:Pogrubienie'
$Italic{'Polish'} = ':Format:Kursywa'
$Shadow{'Polish'} = ':Format:Cień'
$ConvertToTable{'Polish'} = ':Tabela:Konwertuj do Tabeli'
$MergeCells{'Polish'} = ':Tabela:Scal Komórki'
$AlignCellsCenter{'Polish'} = ':Tabela:Wyrównaj Komórki:Środek'
$AlignCellsMiddle{'Polish'} = ':Tabela:Wyrównaj Komórki:Środek'
$SmallCaps{'Spanish'} = ':Formato:Mayúsculas/minúsculas:Mostrar como versalitas'
$Bold{'Spanish'} = ':Formato:Negrita'
$Italic{'Spanish'} = ':Formato:Cursiva'
$Shadow{'Spanish'} = ':Formato:Sombra'
$ConvertToTable{'Spanish'} = ':Tabla:Convertir a tabla'
$MergeCells{'Spanish'} = ':Tabla:Fundir celdas'
$AlignCellsCenter{'Spanish'} = ':Tabla:Alinear celdas:Centrar'
$AlignCellsMiddle{'Spanish'} = ':Tabla:Alinear celdas:Mitad'
Insert Attributed Text $calData
Menu $ConvertToTable{$lproj}
Menu $AlignCellsCenter{$lproj}
Menu $AlignCellsMiddle{$lproj}
$tableSel = $doc.tableSelection
$table = $tableSel.table
# Set style attibutes of the first row, e.g. July 2009
$1stRow = Range.new 0, 1
$1stRowSel = TableSelection.new $table, $1stRow
$doc.setSelection $1stRowSel
Menu $MergeCells{$lproj}
Menu $Bold{$lproj}
Menu $Shadow{$lproj}
$sel = TextSelection.active
$attr = $sel.text.displayAttributesAtIndex $sel.location
$kern = $attr.fontSize / 12
Set Kerning $kern
# Set style attibutes of the second row (Sun Mon Tue Wed Thr Fri Sat)
$2ndRow = Range.new 1, 1
$2ndRowSel = TableSelection.new $table, $2ndRow
$doc.setSelection $2ndRowSel
Menu $Bold{$lproj}
Menu $Italic{$lproj}
Menu $SmallCaps{$lproj}
$dataRows = Range.new 1, $table.rowCount - 1
# Set Sunday color
#$1stCol = Range.new 0, 1
#$Sundays = TableSelection.new $table, $dataRows, $1stCol
#$doc.setSelection $Sundays
#Set Text Color $SundayColor
$7thCol = Range.new 6, 1
$Sundays = TableSelection.new $table, $dataRows, $7thCol
$doc.setSelection $Sundays
Set Text Color $SundayColor
# Set Saturday color
#$7thCol = Range.new 6, 1
#$Saturdays = TableSelection.new $table, $dataRows, $7thCol
#$doc.setSelection $Saturdays
#Set Text Color $SaturdayColor
$6thCol = Range.new 5, 1
$Saturdays = TableSelection.new $table, $dataRows, $6thCol
$doc.setSelection $Saturdays
Set Text Color $SaturdayColor
$doc.setSelection $origSel # move the caret to the original location
### end of macro ###