Farbflash projects: Imaging lingo table | 3-D scene list | Find all | Handler menu | Lingo message window

source: trunk/lingosource/castlib1/bbedit_Utilities.ls

Last change on this file was 257, checked in by alex, 8 months ago

updated to D11 format

File size: 47.1 KB
Line 
1-- bbedit_Utilities
2-----------------------------------
3-- PROPERTIES:
4--!memberProperties: [#name: "bbedit_Utilities", #scripttype: #parent, #scriptSyntax: #lingo, #comments: "~/Documents/Scripts/lingo/commonMovieScript.ls"]
5--
6-- DESCRIPTION:
7--               This script externalizes all functions which are related to the use of an external editor for script editing
8--               It started as interface to BBEdit, hence the name, later I added support for arbitrary editors
9--               as there is not BBEdit for windows. I tested with UltraEdit and Tortoise SVN for the merge/diff functionality
10--               I'd appreciate any enhencements made for other external editors, but the above are the ones I use
11--               and therefore I haven't tested against others
12--
13-- REQUIRES:
14--               script "alexUtilities" -> ancestor -> basic function provider
15--               most functionality is provided through the shell xtra and buddyApi xtra
16--               although it should fail gracefully, if those are not present
17--               not much will work without them
18--
19-- USAGE:
20--               This script is instantiated and used in the "tell the stage" block and one of the functions
21--               which are defined in script "OSCmenu_Utilities" and which was selected by the user
22--               will be executed in "stage scope". That means, that references are made form within the stage context
23--               e.g. member("foo") will refer to a member in one of the stages castlibs
24--               sprite(x) will refere to sprite(x) in the stages score and so on
25--
26--               Please see the descriptions of many of those handlers at: http://www.farbflash.org/trac/HandlerMenu/wiki/utilityHandlers
27-----------------------------------
28
29property ancestor
30
31on new me
32  ancestor = new(script "alexUtilities")
33  return me
34end
35
36
37-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
38on _______________BBEDIT_SCRIPTS end
39end
40-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
41
42on mOpen_Linked_Script_With_BBedit me, editor
43 
44  if  mCheckForXtra(me, "ff_shell") = 0 then
45    if mCheckForXtra(me, "Shell") = 0 then
46      mShellXtraMissing me
47      exit
48    end if
49  end if
50 
51  cl = the activecastlib
52  sel = the selection of castlib cl
53 
54  editor = string(editor)
55  if length(editor) < 1 then
56    clistr = mFindUnixAppInPath(me, "bbedit")
57    if length(clistr) < 1 then
58      alert "BBedit not found in your path!"
59      exit
60    end if
61  else
62    clistr = QUOTE & editor & QUOTE
63  end if
64 
65  repeat with sub in sel
66    repeat with mem = sub[1] to sub[2]
67      memref = member(mem,cl)   
68      if memref.type = #script then
69        fname = memref.filename
70        if fname.length then
71         
72          ppath = mConvertHFS2Unix(me, fname)
73          -- ppath = mDoShellCmd(me, "osascript -e " & QUOTE & "return POSIX path of \" & QUOTE & fname & "\" & QUOTE & QUOTE)
74         
75          if charToNum(the last char of ppath) = 10 then delete the last char of ppath
76          put " " & QUOTE & ppath & QUOTE after clistr
77         
78        else
79          comm = line 1 of memref.comments
80          if length(comm) > 0 then
81            if char 1 of comm = "~" then put "$HOME" into char 1 of comm
82            put " " & QUOTE & comm & QUOTE after clistr
83          end if
84        end if
85      end if
86    end repeat
87  end repeat
88 
89 
90  mDoShellCmd(me, clistr)
91 
92end
93
94-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
95
96on mOpen_Linked_Script_With_ext_editor me
97  editor = mGetExternalScriptEditor(me)
98  if length(editor) < 1 then exit
99  mOpen_Linked_Script_With_BBedit me, editor
100end 
101
102-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
103
104on mEdit_text_with_BBedit me
105  mOpen_text_with_BBedit me, 1
106end
107
108-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
109
110on mOpen_text_with_BBedit me, doLiveEdit
111 
112  if not(the platform contains "mac") then
113    alert "Sorry, BBEdit is a mac application!" & RETURN & "If you change this handler to match something appropriate for Windows, please drop me a note. alex@farbflash.de"
114    exit
115  end if
116 
117  if  mCheckForXtra(me, "ff_shell") = 0 then
118    if mCheckForXtra(me, "Shell") = 0 then
119      mShellXtraMissing me
120      exit
121    end if
122  end if
123 
124  bbeditBinary = mFindUnixAppInPath(me, "bbedit")
125  if length(bbeditBinary) < 1 then
126    alert "BBEdit was not found in your PATH!"
127    exit
128  end if
129 
130  cl = the activecastlib
131  sel = the selection of castlib cl
132 
133  repeat with sub in sel
134    repeat with mem = sub[1] to sub[2]
135     
136      memref = member(mem,cl)
137     
138      theText = ""
139      theType = memref.type
140      if theType = #script then
141        theText = memref.scripttext
142      else if theType = #text then
143        theText = memref.html
144      else if theType = #field then
145        theText = memref.text
146      end if
147     
148      if length(theText) > 0 then
149       
150        if doLiveEdit then
151          ---------------------
152          -- create a temporary file from scripttext:
153          tempSrcHFSPath = mGetTempFilePath(me, "temp_BBEdit_file.ls")
154          tempSrcPath = mConvertHfs2Unix(me, tempSrcHFSPath)
155         
156         
157          theResult = mSaveTextToTempFile(me, theText, tempSrcHFSPath)
158          ---------------------
159         
160          if theResult = 0 then
161            alert "Unable to save file:" && tempSrcHFSPath
162          else
163            mDoShellCmd(me, bbeditBinary && "--wait --resume " & tempSrcPath)
164           
165            theText = mGetTextFromFile(me, tempSrcHFSPath)
166           
167            if length(theText) < 1 then
168              alert "Something seems wrong: the length of the new text is 0, nothing changed. If this was apparently an empty text, please delete by hand."
169            else
170              if theType = #script then
171                memref.scripttext = theText
172              else if theType = #text then
173                memref.html = theText
174              else if theType = #field then
175                memref.text = theText
176              end if
177            end if
178          end if
179         
180        else
181         
182          theName = memref.name
183          if length(theName) < 1 then
184            theName = "member_" & memref.membernum & "_" & memref.castlibnum
185          end if
186         
187          tempSrcHFSPath = mGetTempFilePath(me, theName & ".ls")
188          tempSrcPath = mConvertHfs2Unix(me, tempSrcHFSPath)
189         
190         
191          theResult = mSaveTextToTempFile(me, theText, tempSrcHFSPath)
192         
193          if theResult = 0 then
194            alert "Unable to save temp file:" && tempSrcHFSPath
195          else
196            mDoShellCmd(me, bbeditBinary && tempSrcPath)
197          end if
198         
199        end if
200       
201      end if
202    end repeat
203  end repeat
204 
205end
206
207
208-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
209
210on mEdit_text_in_ext_editor me
211  mOpen_text_with_ext_editor me, 1
212end
213
214-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
215
216on mGetMacBinary me, editor
217  if not(editor starts "/") then
218    editor = mConvertHFS2Unix(me, editor)
219  end if
220 
221  if the last char of editor = "/" then delete the last char of editor
222 
223  olddelim = the itemdelimiter
224  the itemdelimiter = "/"
225 
226  appname = the last item of editor
227  if offset(".app", appname) = length(appname) - 3 then
228    infoplist = editor & "/Contents/Info.plist"
229    exename = mDoShellCmd(me, "grep -A1 -E '<key>CFBundleExecutable<\/key>'" && QUOTE & infoplist & QUOTE & " | grep -vE '<key>CFBundleExecutable</key>' | cut -d\> -f2 | cut -d\< -f1")
230    if the last char of exename = RETURN then delete the last char of exename
231    if the last char of exename = numToChar(10) then delete the last char of exename
232    editor = editor & "/Contents/MacOS/" & exename
233  end if
234 
235  the itemDelimiter = olddelim
236 
237  return editor
238end
239
240-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
241
242on mOpen_text_with_ext_editor me, doLiveEdit
243 
244  if  mCheckForXtra(me, "ff_shell") = 0 then
245    if mCheckForXtra(me, "Shell") = 0 then
246      mShellXtraMissing me
247      exit
248    end if
249  end if
250 
251  cl = the activecastlib
252  sel = the selection of castlib cl
253 
254  isMac = (the platform contains "mac")
255 
256  editor = mGetExternalScriptEditor(me)
257  if length(editor) < 1 then exit
258 
259  repeat with sub in sel
260    repeat with mem = sub[1] to sub[2]
261     
262      memref = member(mem,cl)
263     
264      theText = ""
265      theType = memref.type
266      if theType = #script then
267        theText = memref.scripttext
268      else if theType = #text then
269        theText = memref.html
270      else if theType = #field then
271        theText = memref.text
272      end if
273     
274      if length(theText) > 0 then
275       
276       
277        if doLiveEdit then
278          ---------------------
279          tempSrcHFSPath = mGetTempFilePath(me, "temp_LingoScript_file.ls")
280         
281          if isMac then
282            waitparam = ""
283            editor = mGetMacBinary(me, editor)
284            tempSrcPath = mConvertHfs2Unix(me, tempSrcHFSPath)
285          else
286            waitparam = " /wait"
287            tempSrcPath = tempSrcHFSPath
288          end if
289          ---------------------
290         
291          theResult = mSaveTextToTempFile(me, theText, tempSrcHFSPath)
292         
293          if theResult = 0 then
294            alert "Unable to save temp file:" && tempSrcHFSPath
295          else
296           
297            mDoShellCmd(me, QUOTE & editor & QUOTE && tempSrcPath & waitparam)
298           
299            theText = mGetTextFromFile(me, tempSrcHFSPath)
300           
301            if length(theText) < 1 then
302              alert "Temp file:" && tempSrcHFSPath && "contains no text. Changes will not be written to script."
303             
304            else
305             
306              theText = mForceMacLineBreaks(me, theText)
307             
308              if theType = #script then
309                memref.scripttext = theText
310              else if theType = #text then
311                memref.html = theText
312              else if theType = #field then
313                memref.text = theText
314              end if
315             
316            end if
317           
318          end if
319         
320         
321        else
322         
323          theName = memref.name
324          if length(theName) < 1 then
325            theName = "member_" & memref.membernum & "_" & memref.castlibnum
326          end if
327          ---------------------
328          -- create a temporary file from scripttext:
329          tempSrcHFSPath = mGetTempFilePath(me, theName & ".ls")
330         
331          if isMac then
332            waitparam = " &"
333            editor = mGetMacBinary(me, editor)
334            tempSrcPath = mConvertHfs2Unix(me, tempSrcHFSPath)
335          else
336            waitparam = ""
337            tempSrcPath = tempSrcHFSPath
338          end if
339         
340          theResult = mSaveTextToTempFile(me, theText, tempSrcHFSPath)
341          ---------------------
342         
343          if theResult = 0 then
344            alert "Unable to save temp file:" && tempSrcHFSPath
345          else
346            mDoShellCmd(me, QUOTE & editor & QUOTE && tempSrcPath & waitparam)
347          end if
348         
349        end if
350       
351      end if
352    end repeat
353  end repeat
354 
355end
356
357-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
358
359on mReImport_text_Opened_In_ext_editor me
360  mReImport_text_Opened_In_BBedit me
361end
362
363-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
364
365on mReImport_text_Opened_In_BBedit me
366 
367  cl = the activecastlib
368  sel = the selection of castlib cl
369 
370  repeat with sub in sel
371    repeat with mem = sub[1] to sub[2]
372     
373      memref = member(mem,cl)
374     
375      theName = memref.name
376      if length(theName) < 1 then
377        theName = "member_" & memref.membernum & "_" & memref.castlibnum
378      end if
379     
380      tempSrcPath = mGetTempFilePath(me, theName & ".ls")
381     
382      theText = mGetTextFromFile(me, tempSrcPath)
383     
384      if length(theText) > 0 then
385       
386        theText = mForceMacLineBreaks(me, theText)
387       
388        case memref.type of
389          #script: memref.scripttext = theText
390          #text: memref.html = theText
391          #field: memref.text = theText
392        end case
393       
394      else
395        alert "Temp file:" && tempSrcPath && "contains no text. Changes will not be written to script."
396       
397      end if
398     
399    end repeat
400  end repeat
401 
402end
403
404-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
405
406on mForceMacLineBreaks me, theText
407  rettext = ""
408  olddelim = the itemdelimiter
409  the itemdelimiter = numToChar(10)
410  thirteen = numToChar(13)
411  num = the number of items of theText
412  repeat with n = num down to 1
413    i = item n of theText
414    put i after rettext
415    if the last char of i <> thirteen then put thirteen after rettext
416  end repeat
417  the itemdelimiter = olddelim
418  return rettext
419end
420
421-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
422
423on mCompareSelectedScriptmembersBatch me
424 
425  if not(the platform contains "mac") then
426    alert "Sorry, BBEdit is a mac application!" & RETURN & "If you change this handler to match something appropriate for Windows, please drop me a note. alex@farbflash.de"
427    exit
428  end if
429 
430  if  mCheckForXtra(me, "ff_shell") = 0 then
431    if mCheckForXtra(me, "Shell") = 0 then
432      mShellXtraMissing me
433      exit
434    end if
435  end if
436 
437  bbeditBinary = mFindUnixAppInPath(me, "bbedit")
438  if length(bbeditBinary) < 1 then
439    alert "BBEdit was not found in your PATH!"
440    exit
441  end if
442 
443  bbdiffpath = mFindUnixAppInPath(me, "bbdiff")
444  if length(bbdiffpath) < 1 then
445    alert "Consider installing BBEdits command line tools. If we could use bbdiff it would be way nicer."
446  else
447    if mCheckForXtra(me, "FileIO") = 0 then
448      alert "FileIO Xtra missing!"
449      exit
450    end if
451  end if
452 
453  textlist = []
454 
455  cl = the activecastlib
456  sel = the selection of castlib cl
457 
458  memberlist = []
459  repeat with sub in sel
460    repeat with mem = sub[1] to sub[2]
461      memberlist.add(member(mem,cl))
462    end repeat
463  end repeat
464 
465  cnt = count(memberlist)
466  if (cnt mod 2) or (cnt = 0) then
467    alert "Must be an even number of selected members"
468    exit
469  end if
470  cnt = cnt/2
471 
472  doit = 0
473 
474  repeat with n = 1 to cnt
475   
476    theText = ""
477   
478    memref = memberlist[n]
479    if memref.type = #script then
480      theText = memref.scripttext
481    else if [#text, #field].getPos(memref.type) > 0 then
482      theText = memref.text
483    end if
484   
485   
486   
487    if length(theText) > 0 then
488     
489     
490      fname = memref.name
491      if length(fname) > 24 then
492        fname = fname.char[1 .. 20] & "..." & fname.char[length(fname)]
493      end if
494      fname = fname & "___" & memref.membernum
495     
496     
497      theText2 = ""
498     
499      memref2 = memberlist[n+cnt]
500      if memref2.type = #script then
501        theText2 = memref2.scripttext
502      else if [#text, #field].getPos(memref2.type) > 0 then
503        theText2 = memref2.text
504      end if
505     
506      if length(theText2) > 0 then
507       
508        name1 = memref.name
509        if length(name1) < 1 then name1 = string(memref)
510        name2 = memref2.name
511        if length(name2) < 1 then name2 = string(memref2)
512       
513        if theText = theText2 then
514         
515          put "Members " & name1 & " and " & name2 & " are identical"
516         
517        else
518         
519          put "Members " & name1 & " and " & name2 & " differ"
520         
521          if length(bbdiffpath) < 1 then
522           
523            --------------------------------------------- the old version created new documents in bbedit and I selected "diff" for each from the menu
524            --------------------------------------------- bbdiff is cooler ;-)
525            oldclipboardNum = new(#field)
526            oldclipboardNum.pasteClipBoardInto()
527           
528            neuer = new(#field)
529           
530            neuer.text = theText
531            copyToClipBoard(neuer)
532            mDoShellCmd(me, "pbpaste |" && bbeditBinary)
533           
534           
535            neuer.text = theText2
536            copyToClipBoard(neuer)
537            mDoShellCmd(me, "pbpaste |" && bbeditBinary)
538           
539           
540           
541            if oldclipboardNum.type <> #empty then copyToClipBoard(oldclipboardNum)
542            oldclipboardNum.erase()
543            neuer.erase()
544            --------------------------------------------
545           
546          else
547           
548            if doit = 0 then
549             
550              --              tempSrcPath = mDoShellCmd(me, "mktemp -d -t temp_BBDiff_folder1", 1)
551              --              tempSrcPath = tempSrcPath[1] & "/"
552             
553              tempSrcPath = "/tmp/temp_BBDiff_folder1/"
554             
555              mDoShellCmd(me, "mkdir -p " & tempSrcPath)
556              mDoShellCmd(me, "rm -r " & tempSrcPath)
557             
558              -- tempSrcHFSPath = mDoShellCmd(me, "osascript -e" && QUOTE & "return POSIX file \" & QUOTE & tempSrcPath & "\" & QUOTE & " as string" & QUOTE, 1)
559              -- tempSrcHFSPath = tempSrcHFSPath[1]
560              tempSrcHFSPath = mConvertUnix2Hfs(me, tempSrcPath)
561             
562             
563              --              tempTgtPath = mDoShellCmd(me, "mktemp -d -t temp_BBDiff_folder2", 1)
564              --              tempTgtPath = tempTgtPath[1] & "/"
565             
566              tempTgtPath = "/tmp/temp_BBDiff_folder2/"
567             
568              mDoShellCmd(me, "mkdir -p " & tempTgtPath)
569              mDoShellCmd(me, "rm -r " & tempTgtPath)
570             
571              --tempTgtHFSPath = mDoShellCmd(me, "osascript -e" && QUOTE & "return POSIX file \" & QUOTE & tempTgtPath & "\" & QUOTE & " as string" & QUOTE, 1)
572              --tempTgtHFSPath = tempTgtHFSPath[1]
573              tempTgtHFSPath = mConvertUnix2Hfs(me, tempTgtPath)
574             
575              doit = 1
576            end if
577           
578            mSaveTextToTempFile(me, theText, tempSrcHFSPath & fname)
579            mSaveTextToTempFile(me, theText2, tempTgtHFSPath & fname)
580           
581          end if
582         
583        end if
584       
585      else
586        put "skipping" && memref && "and" && memref2 && "because the length of the text of" && memref2 && "is 0"
587      end if
588     
589    else
590      put "skipping" && memref && "because the length of the text is 0"
591    end if
592   
593  end repeat
594 
595  --  put "mCompareSelectedScriptmembers 7"
596 
597  if doit = 1 then
598    --    put bbdiffpath && QUOTE & tempSrcPath & QUOTE && QUOTE & tempTgtPath & QUOTE
599   
600    mDoShellCmd(me, QUOTE & bbdiffpath & QUOTE && QUOTE & tempSrcPath & QUOTE && QUOTE & tempTgtPath & QUOTE)
601   
602  else
603   
604    --    put "doit = 0"
605   
606    if length(bbdiffpath) > 0 then
607      alert "No differences found"
608    end if
609   
610  end if
611 
612end
613
614
615-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
616
617
618on mBBDiff me, memref1, memref2
619 
620  memref1 = member(memref1)
621 
622 
623  if not(the platform contains "mac") then
624    alert "Sorry, BBEdit is a mac application!" & RETURN & "If you change this handler to match something appropriate for Windows, please drop me a note. alex@farbflash.de"
625    exit
626  end if
627 
628  if  mCheckForXtra(me, "ff_shell") = 0 then
629    if mCheckForXtra(me, "Shell") = 0 then
630      mShellXtraMissing me
631      exit
632    end if
633  end if
634 
635 
636  bbdiffpath = mFindUnixAppInPath(me, "bbdiff")
637  if length(bbdiffpath) < 1 then
638    alert "This function only works with BBDiff, a command line tool provided by BBEdit. Consider installing BBEdits command line tools, it is really helpful."
639    exit
640  end if
641 
642  ---------------------
643  -- create a temporary file from scripttext:
644 
645  tempSrcHFSPath = mGetTempFilePath(me, "temp_BBDiff_file1.ls")
646  tempSrcPath = mConvertHfs2unix(me, tempSrcHFSPath)
647 
648  st1 = memref1.scripttext
649  theResult = mSaveTextToTempFile(me, st1, tempSrcHFSPath)
650 
651  if theResult = 0 then
652    alert "Problems saving file:" && tempSrcHFSPath && "Can't proceed"
653    exit
654  end if
655  ---------------------
656 
657 
658 
659  if not(voidP(memref2)) then memref2 = member(memref2)
660 
661  ----------- there are 2 options for this handler:
662 
663  if ilk(memref2) = #member then -- option 1: we have a second member and diff against the second member
664   
665    st2 = memref2.scripttext
666    if st1 = st2 then
667      put "identical scripttext"
668      exit
669    end if
670   
671    ---------------------
672    -- create a temporary file from scripttext:
673    tempSrcHFSPath2 = mGetTempFilePath(me, "temp_BBDiff_file2.ls")
674    tempSrcPath2 = mConvertHfs2unix(me, tempSrcHFSPath2)
675   
676    comm = tempSrcPath2
677   
678    theResult = mSaveTextToTempFile(me, st2, tempSrcHFSPath2)
679    if theResult = 0 then
680      alert "Problems saving file:" && tempSrcHFSPath && "Can't proceed"
681      exit
682    end if
683    ---------------------
684   
685  else -- option 2: we have NO second member and diff against the file at the path in the member comments (=> alex linked scripts UNIX(!) path)
686    comm = line 1 of memref1.comments
687   
688  end if
689 
690 
691 
692  if comm.length then -- comm is our second file, we only diff, if there is either a second member OR a path in member.comments
693   
694    if char 1 of comm = "~" then
695      put mDoShellCmd(me, "echo -n $HOME") into char 1 of comm
696    end if
697   
698    mDoShellCmd(me, QUOTE & bbdiffpath & QUOTE & " --ignore-curly-quotes --ignore-spaces --wait --resume " &QUOTE& tempSrcPath &QUOTE&&QUOTE& comm &QUOTE)
699   
700    -- since we used the --wait and the --resume switch, we will only come to this line AFTER the diff process in bbedit is finished
701   
702   
703    -------- now write the results of the BBEdit diff back into the script members
704    memref1.scripttext = mGetTextFromFile(me, tempSrcHFSPath)
705   
706    if ilk(memref2) = #member then
707      memref2.scripttext = mGetTextFromFile(me, tempSrcHFSPath2)
708    end if
709   
710   
711  else
712   
713    alert "member has no comments!"
714   
715  end if
716 
717end
718
719-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
720
721on mBBDiff_LiveCompare_SelectedScript me
722  cl = the activecastlib
723  sel = the selection of castlib cl
724  if count(sel) > 0 then
725    memref1 = member(sel[1][1], cl)
726    if sel[1][2] <> sel[1][1] then
727      memref2 = member(sel[1][2], cl)
728    else
729      if count(sel) < 2 then
730        alert "Please select two castmembers!"
731        exit
732      end if
733      memref2 = member(sel[2][1], cl)
734    end if
735    mBBDiff me, memref1, memref2
736  end if
737end
738
739
740-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
741
742on mLiveCompare_SelectedScript me, convertLineBreaksToUnix
743 
744  cl = the activecastlib
745  sel = the selection of castlib cl
746 
747  if count(sel) > 0 then
748    memref1 = member(sel[1][1], cl)
749    if sel[1][2] <> sel[1][1] then
750      memref2 = member(sel[1][2], cl)
751    else
752      if count(sel) < 2 then
753        alert "Please select two castmembers!"
754        exit
755      end if
756      memref2 = member(sel[2][1], cl)
757    end if
758  else
759    alert "Please select two castmembers!"
760    exit
761  end if
762 
763  memtype = memref1.type
764  if [#script, #field, #text].getPos(memtype) < 1 then
765    alert "The members must be either #script, #field or #text members!"
766    exit
767  else
768    case memtype of
769       
770        -----------------------
771      #script:
772        ext1 = ".ls"
773        st1 = memref1.scripttext
774       
775        -----------------------
776      #text:
777        ext1 = ".html"
778        st1 = memref1.html
779       
780        -----------------------
781      otherwise:
782        ext1 = ".txt"
783        st1 = memref1.text
784       
785    end case
786   
787  end if
788 
789  memtype = memref2.type
790  if [#script, #field, #text].getPos(memtype) < 1 then
791    alert "The members must be either #script, #field or #text members!"
792    exit
793  else
794    case memtype of
795       
796        -----------------------
797      #script:
798        ext2 = ".ls"
799        st2 = memref2.scripttext
800       
801        -----------------------
802      #text:
803        ext2 = ".html"
804        st2 = memref2.html
805       
806        -----------------------
807      otherwise:
808        ext2 = ".txt"
809        st2 = memref2.text
810       
811    end case
812  end if
813 
814  if not(the platform contains "mac") then
815   
816    bbdiffpath = mGetSVNDiffBinaryPath(me)
817   
818    if length(bbdiffpath) < 1 then exit
819   
820    isMac = 0
821  else
822    isMac = 1
823    bbdiffpath = mFindUnixAppInPath(me, "bbdiff")
824    if length(bbdiffpath) < 1 then
825      alert "This function only works with BBDiff, a command line tool provided by BBEdit. Consider installing BBEdits command line tools, it is really helpful."
826      exit
827    end if
828   
829  end if
830 
831 
832  if  mCheckForXtra(me, "ff_shell") = 0 then
833    if mCheckForXtra(me, "Shell") = 0 then
834      mShellXtraMissing me
835      exit
836    end if
837  end if
838 
839 
840  name1 = memref1.name & "_m" & memref1.memberNum & "_c" & memref1.castlibnum
841  fname1 = mGetTempFilePath(me, name1 & ext1)
842 
843  name2 = memref2.name & "_m" & memref2.memberNum & "_c" & memref2.castlibnum
844  fname2 = mGetTempFilePath(me, name2 & ext2)
845 
846  ------------------------------------------ trac subversion support works better with unix linebreaks...
847  if voidP(convertLineBreaksToUnix) then convertLineBreaksToUnix = 1
848  if convertLineBreaksToUnix = "" then convertLineBreaksToUnix = 1
849 
850  if convertLineBreaksToUnix = 1 then
851    st1 = mConvertLineBreaksToUnix(me, st1)
852    st2 = mConvertLineBreaksToUnix(me, st2)
853  end if
854  -----------------------------------------
855 
856 
857  theResult = mSaveTextToTempFile(me, st1, fname1)
858  theResult = mSaveTextToTempFile(me, st2, fname2)
859  ---------------------
860 
861 
862  if isMac then
863   
864   
865    theResult = mDoShellCmd(me, QUOTE & bbdiffpath & QUOTE & " --ignore-curly-quotes --ignore-spaces --wait --resume " &QUOTE& mConvertHFS2Unix(me, fname1) &QUOTE&&QUOTE& mConvertHFS2Unix(me, fname2) &QUOTE && "2>&1", RETURN, 0, 1)
866   
867    -- since we used the --wait and the --resume switch, we will only come to this line AFTER the diff process in bbedit is finished
868   
869    if count(theResult) > 0 then
870      if theResult[1] contains "no such file or directory" then
871        put theResult[1]
872      else
873        put "No differences found for member: " & memref1.name && "(" & memref1 & ") and " & memref2.name && "(" & memref2 & ")"
874      end if
875      writeBack = 0
876     
877    else
878     
879      -------- now write the results of the BBEdit diff back into the script members
880      st1 = mGetTextFromFile(me, fname1)
881      st2 = mGetTextFromFile(me, fname2)
882     
883      writeBack = 1
884     
885    end if
886   
887    ---------------------- windows
888  else
889   
890   
891    theResult = mDoShellCmd(me, QUOTE & bbdiffpath & QUOTE && QUOTE & fname1 &QUOTE&&QUOTE& fname2 &QUOTE, RETURN, 0, 0, 0)
892   
893    -------- now write the results of the BBEdit diff back into the script members
894    st1 = mGetTextFromFile(me, fname1)
895    st2 = mGetTextFromFile(me, fname2)
896   
897    writeBack = 1
898  end if
899 
900 
901  if writeBack = 1 then
902   
903   
904    if convertLineBreaksToUnix = 1 then
905      st1 = mConvertLineBreaksToMac(me, st1)
906      st2 = mConvertLineBreaksToMac(me, st2)
907    end if
908   
909    memtype = memref1.type
910    case memtype of
911        -----------------------
912      #script:
913        memref1.scripttext = st1
914       
915        -----------------------
916      #text:
917        memref1.html = st1
918       
919        -----------------------
920      otherwise:
921        memref1.text = st1
922       
923    end case
924   
925    memtype = memref2.type
926    case memtype of
927        -----------------------
928      #script:
929        memref2.scripttext = st2
930       
931        -----------------------
932      #text:
933        memref2.html = st2
934       
935        -----------------------
936      otherwise:
937        memref2.text = st2
938       
939    end case
940   
941  end if
942 
943 
944end
945
946
947
948
949
950-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
951on _______________LINKED_SCRIPTS_HANDLERS me
952end
953-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
954
955
956-- LINKED SCRIPTS
957-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
958
959-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
960-- refresh the linked member after the source of the linked script was changed
961
962on mRefreshScripts me
963 
964  CurrentOSXUserName = ""
965  isMac = (the platform contains "mac")
966  if isMac then CurrentOSXUserName = mGetCurrentOSXUserName(me)
967 
968  cl = the activecastlib
969  sel = the selection of castlib cl
970  anz = sel.count
971  repeat with n = 1 to anz
972    repeat with m = sel[n][1] to sel[n][2]
973      memref = member(m, cl)
974      if length(memref.filename) then
975        memref.filename = memref.filename
976      else
977        if memref.type = #script then
978          aPath = mGetFilePathFromMemberComments(me, memref, isMac, CurrentOSXUserName)
979          if length(aPath) > 0 then
980            dertext = mGetTextFromFile(me, aPath)
981            if length(dertext) > 0 then
982              put "updating scripttext of member:" memref.name && "(" & memref & ")"
983              memref.scripttext = dertext
984            end if
985          end if
986        end if
987      end if
988    end repeat
989  end repeat
990end
991
992
993-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
994-- unlink all linked scripts from all castlibs (when transferring a movie to another machine or before publishing)
995
996on mUnLinkAllScripts me
997  cnum = the number of castlibs
998  repeat with l = 1 to cnum
999    mnum = the number of members of castlib l
1000    repeat with n = 1 to mnum
1001      memref = member(n, l)
1002      if memref.type = #script then
1003        if (memref.linked = 1) then memref.linked = 0
1004      end if
1005    end repeat
1006  end repeat
1007end
1008
1009-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1010-- unlink the selected scriptmembers
1011
1012on mUnLinkScripts me
1013  cl = the activecastlib
1014  sel = the selection of castlib cl
1015  anz = sel.count
1016  repeat with n = 1 to anz
1017    repeat with m = sel[n][1] to sel[n][2]
1018      memref = member(m, cl)
1019      if memref.type = #script then
1020        if (memref.linked = 1) then memref.linked = 0
1021      end if
1022    end repeat
1023  end repeat
1024end
1025
1026-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1027
1028on mGetUserHomeFolderPath me
1029  isMac = (the platform contains "mac")
1030  if isMac then
1031    CurrentOSXUserName = mGetCurrentOSXUserName(me)
1032    return "/Users/" & CurrentOSXUserName
1033  end if
1034 
1035  homedir = baSysFolder("personal")
1036  old = the itemdelimiter
1037  the itemdelimiter = "\"
1038  delete the last item of homedir
1039  delete the last item of homedir
1040  the itemdelimiter = old
1041  return homedir
1042end
1043
1044-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1045-- get the absolute pathname of alex linked library script from members comment
1046-- memref is required => member reference
1047-- isMac and CurrentOSXUserName is optional and will be computed if not provided
1048-- in repeat loops provide these values to avoid recomputing them on each iteration
1049
1050on mGetFilePathFromMemberComments me, memref, isMac, CurrentOSXUserName
1051 
1052  aPath = ""
1053 
1054  mp = the moviepath
1055  if length(mp) < 1 then mp = the applicationpath
1056  delim = the last char of mp
1057  olddelim = the itemdelimiter
1058  the itemdelimiter = delim
1059 
1060  if voidP(isMac) then isMac = (the platform contains "mac")
1061  if isMac then
1062    if voidP(CurrentOSXUserName) then
1063      CurrentOSXUserName = mGetCurrentOSXUserName(me)
1064    end if
1065  end if
1066 
1067  comm = line 1 of memref.comments
1068  if comm.length > 0 then
1069   
1070   
1071    if comm starts "~" then -- OSX current user directory
1072     
1073      put mGetUserHomeFolderPath(me) into char 1 of comm
1074      aPath = comm
1075      --      if isMac then
1076      --        put "/Users/"&CurrentOSXUserName into char 1 of comm
1077      --      else
1078      --        offs = offset("/", comm)
1079      --        repeat while offs > 0
1080      --          put "\" into char offs of comm
1081      --          offs = offset("/", comm)
1082      --        end repeat
1083      --        put baSysFolder("personal") into char 1 to 2 of comm
1084      --        aPath = comm
1085      --      end if
1086    end if
1087   
1088    if comm starts "/" then -- OSX/Unix style path
1089     
1090      if isMac then
1091        hdname = getOsDirectory()
1092        hdname = hdname.item[1]
1093        the itemdelimiter = "/"
1094        delete item 1 of comm
1095        itemCnt = comm.item.count
1096        repeat with i = 1 to itemCnt
1097          put delim & comm.item[i] after hdname
1098        end repeat
1099       
1100        aPath = hdname
1101       
1102      else
1103       
1104        if comm starts "/Users/alex/" then
1105          put mGetUserHomeFolderPath(me) & "\" into char 1 to 12 of comm
1106        end if
1107        aPath = comm
1108       
1109      end if
1110     
1111     
1112    else if comm starts "@" then -- relative path with @
1113     
1114      if delim <> "" then
1115        offs = offset("", comm)
1116        repeat while offs > 0
1117          put delim into char offs of comm
1118          offs = offset("", comm)
1119        end repeat
1120      end if
1121     
1122      if delim <> "\" then
1123        offs = offset("\", comm)
1124        repeat while offs > 0
1125          put delim into char offs of comm
1126          offs = offset("\", comm)
1127        end repeat
1128      end if
1129     
1130      offs = offset("/", comm)
1131      repeat while offs > 0
1132        put delim into char offs of comm
1133        offs = offset("/", comm)
1134      end repeat
1135     
1136      delete char 1 of comm
1137      if char 1 of comm = delim then delete char 1 of comm
1138     
1139      if char 1 of comm = delim then
1140        delete the last item of mp
1141        repeat while char 1 of comm = delim
1142          delete the last item of mp
1143          delete char 1 of comm
1144        end repeat
1145        put delim after mp
1146        aPath = mp & comm
1147      end if
1148     
1149    else -- absolute path
1150      aPath = comm
1151    end if
1152   
1153  end if
1154 
1155  the itemdelimiter = olddelim
1156 
1157  return aPath
1158 
1159end
1160
1161-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1162-- link the selected scriptmembers to the files specified in the first line of the members comments
1163
1164on mLinkScripts me
1165 
1166  cl = the activecastlib
1167  sel = the selection of castlib cl
1168 
1169  mp = the moviepath
1170  if length(mp) < 1 then mp = the applicationpath
1171  delim = the last char of mp
1172  olddelim = the itemdelimiter
1173  the itemdelimiter = delim
1174 
1175  isMac = (delim = ":")
1176  if isMac then CurrentOSXUserName = mGetCurrentOSXUserName(me)
1177 
1178  repeat with sub in sel
1179    repeat with mem = sub[1] to sub[2]
1180      memref = member(mem,cl)   
1181      if memref.type = #script then
1182        memname = memref.name
1183        comm = line 1 of memref.comments
1184        if comm.length then
1185         
1186          aPath = mGetFilePathFromMemberComments(me, memref, isMac, CurrentOSXUserName)
1187         
1188          fio = (xtra "fileio").new()
1189          if objectP(fio) then
1190            fio.openFile(aPath, 0)
1191            if fio.status() = 0 then
1192              fio.closeFile()
1193             
1194              scomm = memref.comments
1195              stype = memref.scripttype
1196              sthumb = memref.thumbnail
1197              --                memref.linkAs(aPath)
1198              memref.filename = aPath
1199             
1200              memref.thumbnail = sthumb
1201              memref.scripttype = stype
1202              memref.comments = scomm
1203             
1204            end if
1205          end if
1206          fio = 0
1207         
1208         
1209        else
1210         
1211          if memname.length then
1212           
1213            hdname = getOsDirectory()
1214            anfp = hdname.item[1] & delim & "Users"& delim & CurrentOSXUserName & delim & "Documents"& delim
1215            aPath = anfp & "Scripts"& delim & "lingo"& delim & memname & ".ls"
1216           
1217            fio = (xtra "fileio").new()
1218            if objectP(fio) then
1219              fio.openFile(aPath, 0)
1220              if fio.status() = 0 then
1221                fio.closeFile()
1222               
1223               
1224                stype = memref.scripttype
1225                sthumb = memref.thumbnail
1226               
1227                memref.filename = aPath
1228               
1229                memref.thumbnail = sthumb
1230                memref.scripttype = stype
1231               
1232                --                memref.comments = "/Users/"&mGetCurrentOSXUserName()&"/Documents/Scripts/lingo/" & memname & ".ls"
1233                memref.comments = "~/Documents/Scripts/lingo/" & memname & ".ls"
1234               
1235              else
1236               
1237                aPath = anfp & "ALIEN"& delim & "myLinkedScripts"& delim & memname & ".ls"
1238               
1239                fio.openFile(aPath, 0)
1240                if fio.status() = 0 then
1241                  fio.closeFile()
1242                 
1243                 
1244                  stype = memref.scripttype
1245                  sthumb = memref.thumbnail
1246                 
1247                  memref.filename = aPath
1248                 
1249                  memref.thumbnail = sthumb
1250                  memref.scripttype = stype
1251                  --                  memref.comments = "/Users/"&mGetCurrentOSXUserName()&"/Documents/ALIEN/myLinkedScripts/" & memname & ".ls"
1252                  memref.comments = "~/Documents/ALIEN/myLinkedScripts/" & memname & ".ls"
1253                 
1254                else
1255                  put "member: " & memname && "doesn't have a comment nor a linked script with the member name !"
1256                end if
1257               
1258               
1259              end if
1260            end if
1261            fio = 0
1262           
1263          end if
1264         
1265        end if
1266      end if
1267    end repeat
1268  end repeat
1269 
1270  the itemdelimiter = olddelim
1271 
1272end
1273
1274
1275-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1276
1277on mGetCurrentOSXUserName me
1278 
1279  if mCheckForXtra(me, "FileXtra4") = 1 then
1280    xtraInstance = new(xtra "FileXtra4")
1281    theUser = xtraInstance.fx_FolderGetSpecialPath("kCurrentUserFolderType")
1282    xtraInstance = 0
1283   
1284    olddelim = the itemdelimiter
1285    the itemdelimiter = the last char of the applicationpath
1286    delete the last item of theUser
1287    theUser = the last item of theUser
1288    the itemdelimiter = olddelim
1289   
1290  else if mCheckForXtra(me, "Shell") = 1 or mCheckForXtra(me, "ff_shell") = 1 then
1291    theUser = mDoShellCmd(me, "whoami")
1292    if chartonum(the last char of theUser) = 10 then delete the last char of theUser
1293   
1294  else
1295    theUser = ""
1296   
1297  end if
1298 
1299  return theUser
1300 
1301end
1302
1303
1304-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1305-- compare selected scripts to the .ls script which is defined in their members comments
1306-- if a difference is found some lines will get put into the message window to open the script in bbedit to do a file compare
1307
1308on mCheckLSChange me
1309 
1310 
1311  bbdiffpath = ""
1312  if the platform contains "mac" then
1313   
1314    if mCheckForXtra(me, "Shell") = 1 or mCheckForXtra(me, "ff_shell") = 1 then
1315     
1316      bbeditBinary = mFindUnixAppInPath(me, "bbedit")
1317     
1318      bbdiffpath = mFindUnixAppInPath(me, "bbdiff")
1319      if length(bbdiffpath) < 1 then
1320        alert "Consider installing BBEdits command line tools. If we could use bbdiff it would be way nicer."
1321      end if
1322    end if
1323   
1324    if length(bbdiffpath) > 0 then
1325      if mCheckForXtra(me, "FileIO") = 0 then
1326        alert "FileIO Xtra missing!"
1327        exit
1328      end if
1329    end if
1330   
1331  end if
1332 
1333 
1334  cl = the activecastlib
1335  sel = the selection of castlib cl
1336 
1337  mp = the moviepath
1338  if not mp.length then mp = the applicationpath
1339  delim = the last char of mp
1340  olddelim = the itemdelimiter
1341  the itemdelimiter = delim
1342 
1343  isMac = (the platform contains "mac")
1344  if isMac then CurrentOSXUserName = mGetCurrentOSXUserName(me)
1345 
1346  repeat with sub in sel
1347    repeat with mem = sub[1] to sub[2]
1348      memref = member(mem,cl)   
1349      if memref.type = #script then
1350        memname = memref.name
1351        comm = line 1 of memref.comments
1352       
1353        if length(comm) < 1 then
1354          -- put memref.name && "(" & memref & ") has no comments - not linked"
1355        else
1356         
1357          aPath = mGetFilePathFromMemberComments(me, memref, isMac, CurrentOSXUserName)
1358         
1359          if length(aPath) < 1 then
1360            -- put memref.name && "(" & memref & ") has no comments - not linked"
1361          else
1362           
1363            fio = (xtra "fileio").new()
1364           
1365            if objectP(fio) then
1366             
1367              fio.openFile(aPath, 0)
1368             
1369              if fio.status() <> 0 then
1370                put memref.name && "(" & memref & "): Couldn't open file:" && aPath && "fileIO error:" && fio.error(fio.status())
1371              else
1372               
1373                vergText = fio.readFile()
1374                fio.closeFile()
1375                memscr = memref.scripttext
1376               
1377                if vergText = memscr then
1378                  put memref.name && "(" & memref & ") has no changes"
1379                else
1380                 
1381                  isEqual = 0
1382                  if mCheckForXtra(me, "Pregex") = 1 then
1383                   
1384                    memscrLi = [memscr]
1385                    pregex_replace(memscrLi, "\s", "ig", "")
1386                    memscrLi = memscrLi[1]
1387                   
1388                    vergTextLi = [vergText]
1389                    pregex_replace(vergTextLi, "\s", "ig", "")
1390                    vergTextLi = vergTextLi[1]
1391                   
1392                    isEqual = (memscrLi = vergTextLi)
1393                  end if
1394                 
1395                  if isEqual <> 0 then
1396                    put memref.name && "(" & memref & ") has no changes"
1397                  else
1398                   
1399                    if length(bbdiffpath) < 1 then
1400                     
1401                     
1402                      if not(the platform contains "mac") then
1403                        put "-------------------------------------------------------"
1404                        put RETURN&"neuer = new(#field)"&RETURN&"neuer.text = "&memref&".scripttext"&RETURN&"neuer.copyToClipBoard()"&RETURN&"neuer.erase()"&RETURN
1405                        if length(bbeditBinary) > 0 then
1406                          put RETURN&"shell_cmd("&QUOTE&"PBPaste |" && bbeditBinary && ";" && bbeditBinary && line 1 of memref.comments & QUOTE&")"&RETURN
1407                        else
1408                          put "BBEdit not found in PATH"
1409                        end if
1410                      else
1411                       
1412                        if (mCheckForXtra(me, "Shell") + mCheckForXtra(me, "ff_shell")) = 0  then
1413                          put "-------------------------------------------------------"
1414                          put RETURN&"neuer = new(#field)"&RETURN&"neuer.text = "&memref&".scripttext"&RETURN&"neuer.copyToClipBoard()"&RETURN&"neuer.erase()"&RETURN
1415                          if length(bbeditBinary) > 0 then
1416                            put RETURN&"shell_cmd("&QUOTE&"PBPaste |" && bbeditBinary && ";" && bbeditBinary && line 1 of memref.comments & QUOTE&")"&RETURN
1417                          else
1418                            put "BBEdit not found in PATH"
1419                          end if
1420                        else
1421                         
1422                          neuer = new(#field)
1423                          neuer.text = memscr
1424                          neuer.copyToClipBoard()
1425                          neuer.erase()
1426                         
1427                          comm = line 1 of memref.comments
1428                          if char 1 of comm = "~" then put "$HOME" into char 1 of comm
1429                         
1430                         
1431                          if length(bbeditBinary) > 0 then
1432                            mDoShellCmd(me, "PBPaste |" && bbeditBinary && ";" && bbeditBinary && comm)
1433                          else
1434                            put "BBEdit not found in PATH"
1435                          end if
1436                         
1437                        end if
1438                       
1439                      end if
1440                     
1441                    else
1442                     
1443                      tempSrcHFSPath = mGetTempFilePath(me, "temp_BBEdit_file.ls")
1444                      tempSrcPath = mConvertHfs2unix(me, tempSrcHFSPath)
1445                     
1446                      theResult = mSaveTextToTempFile(me, memref.scripttext, tempSrcHFSPath)
1447                      if theResult <> 0 then
1448                       
1449                        if char 1 of comm = "~" then put "$HOME" into char 1 of comm
1450                       
1451                        mDoShellCmd(me, QUOTE & bbdiffpath & QUOTE & " --ignore-curly-quotes --ignore-spaces --wait --resume " &QUOTE& tempSrcPath &QUOTE&&QUOTE& comm &QUOTE)
1452                       
1453                        newscripttext = mGetTextFromFile(me, tempSrcHFSPath)
1454                        if length(newscripttext) then
1455                          memref.scripttext = mGetTextFromFile(me, tempSrcHFSPath)
1456                        else
1457                          alert "Something seems wrong: the length of the new text is 0, nothing was changed now. If this was puprosely an empty text, please delete by hand."
1458                        end if
1459                       
1460                      end if
1461                     
1462                     
1463                    end if
1464                   
1465                  end if
1466                 
1467                 
1468                end if
1469               
1470              end if
1471             
1472            end if
1473          end if
1474        end if
1475        fio = 0
1476       
1477      end if
1478     
1479    end repeat
1480  end repeat
1481 
1482  the itemdelimiter = olddelim
1483 
1484 
1485end
1486
1487
1488-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1489
1490-- open the associated .ls, which is found in the member comments in bbedit
1491on mBBedit me
1492 
1493  if not(the platform contains "mac") then
1494    alert "Sorry, BBEdit is a mac application!" & RETURN & "If you change this handler to match something appropriate for Windows, please drop me a note. alex@farbflash.de"
1495    exit
1496  end if
1497 
1498  if  mCheckForXtra(me, "ff_shell") = 0 then
1499    if mCheckForXtra(me, "Shell") = 0 then
1500      mShellXtraMissing me
1501      exit
1502    end if
1503  end if
1504 
1505  cl = the activecastlib
1506  sel = the selection of castlib cl
1507 
1508  clistr = mFindUnixAppInPath(me, "bbedit")
1509  if length(clistr) < 1 then
1510    alert "BBEdit was not found in your PATH!"
1511    exit
1512  end if
1513 
1514  -- home = mDoShellCmd(me, "echo -n $HOME")
1515 
1516  repeat with sub in sel
1517    repeat with mem = sub[1] to sub[2]
1518      memref = member(mem,cl)   
1519      if memref.type = #script then
1520        memname = memref.name
1521        comm = line 1 of memref.comments
1522        if comm.length then
1523          if char 1 of comm = "~" then
1524            -- put home into char 1 of comm
1525            put "$HOME" into char 1 of comm
1526          end if
1527          put " "&comm after clistr
1528        end if
1529      end if
1530    end repeat
1531  end repeat
1532 
1533  mDoShellCmd(me, clistr)
1534 
1535end
1536
1537
1538-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1539
1540on mExportListOfUsedLinkedScripts me
1541 
1542  str = ""
1543  clnum = the number of castlibs
1544  repeat with cl = 1 to clnum
1545    anz = the number of members of castlib cl
1546    repeat with n = 1 to anz
1547      memref = member(n, cl)
1548      if memref.type = #script then
1549        comm = line 1 of memref.comments
1550        if length(comm) > 0 then put "Membername:" && memref.name & TAB & "("&comm&")" & Return after str
1551      end if
1552    end repeat
1553  end repeat
1554  delete the last char of str
1555 
1556  mn = the moviename
1557  --  offs = offset(".", mn)
1558  --  if offs > 0 then mn = mn.char[1 .. offs-1]
1559 
1560  spl = mSplitPath(me, mn)
1561 
1562  mSaveToTextFile me, str, "", "Save list of used linked scripts", spl[#basename] & "_linkedScripts_List.txt"
1563 
1564end
Note: See TracBrowser for help on using the repository browser.