1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
property Sep : ";" -- defini le separateur de colonnes du fichier csv
global libelle, largeur, hauteur, Aindex, Nindex
--initialisation
set libelle to {} -- liste des libelles de formats
set largeur to {} -- liste des largeurs de formats
set hauteur to {} -- liste des hauteurs de formats
set Aindex to 0 -- ancien index
set Nindex to 0 -- nouvel index
-- pour les tests
set fichierCSV to (path to desktop as text) & "Formats_Pubs_2.csv"
set Aindex to LitCSVindex(fichierCSV, libelle, largeur, hauteur) --lecture du fichier csv
if Aindex = 0 then set Aindex to 1
tell application "Adobe InDesign CC 2018"
activate
set varDropDownList to libelle
--set varSelectedIndex to 1
set varMinimumWidth to 150
set myEventNames to {"afterNew", "afterUpdate", "afterInvoke", "afterActivate", "afterContextChanged", "afterSelectionAttributeChanged", "afterSelectionChanged", "beforeUpdate"}
set myDialog to make dialog with properties {name:"CHOIX DU FORMAT :"}
tell myDialog
---- DRODPDOWN A
set dlgColumn1 to make dialog column
tell dlgColumn1
set enableGroup1 to make enabling group with properties {static label:"FORMATS A : ", checked state:false}
tell enableGroup1
tell (make dialog column)
set varDropDownA to make dropdown with properties {string list:libelle, selected index:(Aindex - 1), min width:varMinimumWidth}
tell varDropDownA
repeat with myEventName in myEventNames
make event listener with properties {event type:myEventName, handler:my dropdownchange}
end repeat
end tell
end tell
end tell
end tell
---- DRODPDOWN B
set dlgColumn2 to make dialog column
tell dlgColumn2
set enableGroup2 to make enabling group with properties {static label:"FORMATS B : ", checked state:false}
tell enableGroup2
tell (make dialog column)
set varDropDownB to make dropdown with properties {string list:libelle, selected index:(Aindex - 1), min width:varMinimumWidth}
tell varDropDownB
repeat with myEventName in myEventNames
make event listener with properties {event type:myEventName, handler:my dropdownchange}
end repeat
end tell
end tell
end tell
end tell
end tell
--get the results
set myResult to show myDialog
if myResult = true then
-- varDropDown Handler (Dropdown)
set Nindex to ((selected index of varDropDown) + 1)
set varDropDownListChoice to item Nindex of libelle as item
end if
destroy myDialog
end tell
if Nindex is not Aindex then -- index changé, on l'enregistre, sinon, on ne fait rien !
EcritCSV(fichierCSV, libelle, largeur, hauteur, Nindex)
end if
(*
set the_position to indexof(fichierCSV, libelle)
if the_position is 0 then
tell application "Finder"
activate
display dialog "Format non valable"
end tell
end if
*)
-- ************************ FIN DU PROGRAMME PRINCIPAL
on dropdownchange()
tell application "Adobe InDesign CC 2018"
set myEvent to evt
display dialog ("This event is the " & event type of myEvent & " event.")
end tell
end dropdownchange
on LitCSVindex(fcsv, l1, l2, l3)
--lit le fichier localcsv et retourne les listes l1,L2,l3. Renvoie l'index de la derniere ligne avec la colonne 4 non vide
set i to 0
set lignes to every paragraph of (read file fcsv)
set AppleScript's text item delimiters to {Sep}
repeat with n from 1 to (count of lignes)
set end of l1 to text item 1 of (item n of lignes)
set end of l2 to text item 2 of (item n of lignes)
set end of l3 to text item 3 of (item n of lignes)
try
if (text item 4 of (item n of lignes)) is not "" then set i to n
end try
end repeat
return i
end LitCSVindex
on EcritCSV(fcsv, l1, l2, l3, i) -- ecrit le fichier fcsv avec les lignes formées de l1,l2,l3 et un 'X' en ligne i)
set mtexte to ""
repeat with n from 1 to count of l1
if n = i then -- met un X en colonne 4 sur la ligne choisie
set finligne to "X"
else
set finligne to ""
end if
if n = (count of l1) then -- pas de return en dernière ligne
set retour to ""
else
set retour to return
end if
set mtexte to mtexte & (item n of l1) & Sep & (item n of l2) & Sep & (item n of l2) & Sep & finligne & retour
end repeat
try
set fcible to open for access file fcsv with write permission
set eof of fcible to 0
write mtexte to fcible
close access fcible
on error
close access fcs
end try
end EcritCSV
(*
on indexof(theItem, fichierCSV)
set text item delimiters to return
set fichierCSV to return & fichierCSV & return
set text item delimiters to {""}
try
-1 + (count (paragraphs of (text 1 thru (offset of (return & theItem & return) in fichierCSV) of fichierCSV)))
on error
0
end try
end indexof
*) |
Partager