-
Notifications
You must be signed in to change notification settings - Fork 1
/
script
1335 lines (1266 loc) · 43 KB
/
script
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh -x
##########################################################################
#
# Portable Firefox OS X
# $Revision: 4.1
#
# The Contents of this file are made available subject to the terms
# of the following license
#
# - GNU General Public License Version 3
#
# Carlo Gandolfi, Paolo Portaluri January 2010
#
# GNU General Public License Version 3
# =============================================
# Copyright 2006-2011 by:
# Carlo Gandolfi - http://www.freesmug.org
# Paolo Portaluri - http://plus2.it/~paolo/
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##########################################################################
# A 'script' to run "Firefox" as "Portable Firefox OS X" in macOSX
# Revision: 4.1.4
# Modified by:
# Erik T Ashfolk <atErik at Öυť Ĺöōķ dot com> (Öυť=Out,Ĺöōķ=Look) aka "atErik"
#
# Modified to use Pashua dialog (instead of CocoaDialog) & new Platypus,
# etc, for 64bit-only macOSX (Catalina & macOSX after it) compatibility.
#
# The Contents of this new 'script' file are made available subject to
# the terms of the following LICENSE(S)+Restrictions+Permissions:
# - GNU General Public License Version 3 (GPL v3)
# - Do Not Use This To Kill/Harm/Violate(or Steal from)(Any) Human/Community,Earth,etc
# - Copyright © 2020 Erik T Ashfolk (atErik@ÖυťĹöōķ·ċōm, Use basic-latin
# char. No soliciting permitted). All rights reserved.
#
# GNU General Public License Version 3 for this 'script'
# =============================================
#
# A 'script' to run Firefox as portable app on macOSX.
# Copyright © 2020 Erik T Ashfolk (atErik@ÖυťĹöōķ·ċōm, Use basic
# latin char. No soliciting permitted).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# =============================================
#
# This project's primary 'script' is licensed under GPL 3.0 & See-Above
# Pashua is licensed under BSD-3-clause
# Platypus is licensed under BSD-3-Clause
# Firefox (older version) related items are licensed under MPL 1.1
# Firefox (newer version) related items are licensed under MPL 2.0
#
# GPL v3 : https://www.gnu.org/licenses/gpl-3.0.en.html
# BSD (BSD-3-Clause) License:
# https://github.com/atErik/Portable-Firefox-OSX-script/blob/master/BSD-3-clause.txt
# MPL 1.1 License: https://www.mozilla.org/en-US/MPL/1.1/
# MPL 2.0 License: https://www.mozilla.org/en-US/MPL/2.0/
#
# All other trademarks, etc cited here are the property of their respective owners.
# All other copyright items cited here are the copyright of their respective author/creator.
#
#################################################################################
# Reset PATH
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
appID=Firefox
appBin=firefox-bin
# Modified by atErik : Changed below from "userprefbase" into "userPref"
userPref="Library/Application Support"
# Modified by atErik : Changed below from "userpref" into "userPrefBase"
userPrefBase="$HOME/$userPref/$appID/Profiles"
# export userPrefBase
userCacheBase="$HOME/Library/Caches"
userCache="$userCacheBase/$appID"
# PA_userBase="$1/Contents/Resources"
# export PA_userBase
# ========================================================
# Code-lines contributed in StackOverflow.com by "Dave Dopson", is Modified by atErik
# https://stackoverflow.com/questions/59895/
# ========================================================
SrcDir="${BASH_SOURCE[0]}";
DirP="";
# Resolve $SrcDir until the file is no longer a symlink
while [ -h "$SrcDir" ] ; do
DirP="$( cd -P "$( dirname "$SrcDir" )" >/dev/null 2>&1 && pwd )"
SrcDir="$(readlink "$SrcDir")"
# if $SrcDir was a relative symlink, we need to resolve it relative to the path where the symlink file was located
[[ $SrcDir != /* ]] && SrcDir="$DirP/$SrcDir"
done
DirP="$( cd -P "$( dirname "$SrcDir" )" >/dev/null 2>&1 && pwd )"
PA_userBase="$DirP"
unset SrcDir DirP
PA_userPref="$PA_userBase/profile"
copy_pref="$PA_userBase/CopyPref_Done"
CD="$PA_userBase/CocoaDialog.app/Contents/MacOS/CocoaDialog"
# export CD
# Added/Modified by atErik, to use Pashua (instead of CocoaDialog)
PD="$PA_userBase/Pashua.app/Contents/MacOS/Pashua"
# export PD
appICON="$PA_userBase/appIcon.icns"
# export appICON
cautionICON="$PA_userBase/P_${appID}_Caution.icns"
# export cautionICON
# Below line added by atErik, to use bash-functions inside "pashua.sh" file:
# source "$PA_userBase/pashua.sh"
# when above line is enabled, then below 2-functions are not necessary to enable here.
# Temporarily including below 2-functions from "pashua.sh":
# ========================================================
# This section/function copied from Pashua example.sh file
# Pashua’s source code is released under the Open Source Software (3-clause BSD license)
#
# Tries to find the Pashua executable in one of a few default search locations or in
# a custom path passed as optional argument. When it can be found, the filesystem
# path will be in $pashuapath, otherwise $pashuapath will be empty. The return value
# is 0 if it can be found, 1 otherwise.
#
# Argument 1: Path to a folder containing Pashua.app (optional)
# ========================================================
locate_pashua() {
local bundlepath="Pashua.app/Contents/MacOS/Pashua"
local mypath=`dirname "$0"`
pashuapath=""
if [ ! "$1" = "" ]
then
searchpaths[0]="$1/$bundlepath"
fi
searchpaths[1]="$mypath/Pashua"
searchpaths[2]="$mypath/$bundlepath"
searchpaths[3]="./$bundlepath"
searchpaths[4]="/Applications/$bundlepath"
searchpaths[5]="$HOME/Applications/$bundlepath"
for searchpath in "${searchpaths[@]}"
do
if [ -f "$searchpath" -a -x "$searchpath" ]
then
pashuapath=$searchpath
return 0
fi
done
return 1
}
# ========================================================
# This section/function copied from Pashua example.sh file
# Pashua’s source code is released under the Open Source Software (3-clause BSD license)
#
# Function for communicating with Pashua
#
# Argument 1: Configuration string
# Argument 2: Path to a folder containing Pashua.app (optional)
# ========================================================
pashua_run() {
# Write config file
local pashua_configfile=`/usr/bin/mktemp /tmp/pashua_XXXXXXXXX`
echo "$1" > "$pashua_configfile"
locate_pashua "$2"
if [ "" = "$pashuapath" ]
then
>&2 echo "Error: Pashua could not be found"
exit 1
fi
# Get result
local result=$("$pashuapath" "$pashua_configfile")
# Remove config file
rm "$pashua_configfile"
oldIFS="$IFS"
IFS=$'\n'
# Parse result
for line in $result
do
local name=$(echo $line | sed 's/^\([^=]*\)=.*$/\1/')
local value=$(echo $line | sed 's/^[^=]*=\(.*\)$/\1/')
eval $name='$value'
done
IFS="$oldIFS"
}
# ========================================================
# CDokMsg # Modified by atErik : local, "--yes-cancel"/$3, $4/tooltip/tV
# CocoaDialog Ok/Cancel message box
# $1 "text"
# $2 "informative text"
# $3 optional "--no-cancel" = don't show a cancel button, & "--yes-cancel" to show a Cancel button
# $4 optional "tooltip_img|tooltip_text|tooltip_okButton|tooltip_cancelButton", or specify "-" to show no-tooltip
# ========================================================
function CDokMsg { # Modified by atErik : local, "--yes-cancel"/$3, tV/$4/tooltip
local tV=""
local conf="
# Set window title
*.title = $1
# show an image
imgOk.type = image
imgOk.x = 50
imgOk.y = 50
imgOk.maxwidth = 64
imgOk.path = $appICON
# Introductory text
txtOk.type = text
txtOk.default = $2
txtOk.height = 180
txtOk.width = 310
txtOk.x = 50
txtOk.y = 120
# Show an “Ok” general-button at default position
okB.type = button
okB.label = Ok
"
# we will not specify okB.x or okB.y in above,
# so that macOSX can place this general-button at-default position, left-bottom corner
if [ ! -z $3 ] ; then
if [ "$3" == "--yes-cancel" ] ; then
conf="$conf
# Add a “Cancel” button with default-label & show in default-positon
okCB.type = cancelbutton
"
fi;
fi;
if [ ! -z $4 ] ; then
if [ "$4 " != " " ] ; then
if [ "${4%%|*}" != "-" ] ; then
# tooltip msg for image
conf="$conf
imgOk.tooltip = ${4%%|*}
"
fi;
tV=${4#*|}
if [ "${tV%%|*}" != "-" ] ; then
# tooltip msg for text
conf="$conf
txtOk.tooltip = ${tV%%|*}
"
fi;
tV=${tV#*|}
if [ "${tV%%|*}" != "-" ] ; then
# tooltip msg for a button showing “Ok”
conf="$conf
okB.tooltip = ${tV%%|*}
"
fi;
if [ ! -z $3 ] ; then
if [ "$3" == "--yes-cancel" ] ; then
tV=${tV#*|}
if [ "${tV%%|*}" != "-" ] ; then
# tooltip msg for a button showing “Cancel”/etc
conf="$conf
okCB.tooltip = ${tV%%|*}
"
fi;
fi;
fi;
fi;
fi;
beep
pashua_run "$conf" "$PA_userBase"
# beep
# "$CD" ok-msgbox --icon-file "$appICON" \
# --text "$1" --informative-text "$2" "$3"
}
function CDokMsgC { # Modified by atErik : local, "--yes-cancel"/$3, tV/$4/tooltip
local tV=""
local conf="
# Set window title
*.title = $1
# show an image
imgOkC.type = image
imgOkC.x = 50
imgOkC.y = 50
imgOkC.maxwidth = 64
imgOkC.path = $cautionICON
# Introductory text
txtOkC.type = text
txtOkC.default = $2
txtOkC.height = 180
txtOkC.width = 310
txtOkC.x = 50
txtOkC.y = 120
# Show an “Ok” general-button at default position
bOkC.type = button
bOkC.label = Ok
"
# we will not specify okb.x or okb.y in above,
# so that macOSX can place this general-button at-default position, left-bottom corner
if [ ! -z $3 ] ; then
if [ "$3" == "--yes-cancel" ] ; then
conf="$conf
# Add a “Cancel” button with default-label & show in default-positon
cbOkC.type = cancelbutton
"
fi;
fi;
if [ ! -z $4 ] ; then
if [ "$4 " != " " ] ; then
if [ "${4%%|*}" != "-" ] ; then
# tooltip msg for image
conf="$conf
imgOkC.tooltip = ${4%%|*}
"
fi;
tV=${4#*|}
if [ "${tV%%|*}" != "-" ] ; then
# tooltip msg for text
conf="$conf
txtOkC.tooltip = ${tV%%|*}
"
fi;
tV=${tV#*|}
if [ "${tV%%|*}" != "-" ] ; then
# tooltip msg for a button showing “Ok”
conf="$conf
bOkC.tooltip = ${tV%%|*}
"
fi;
if [ ! -z $3 ] ; then
if [ "$3" == "--yes-cancel" ] ; then
tV=${tV#*|}
if [ "${tV%%|*}" != "-" ] ; then
# tooltip msg for a button showing “Cancel”/etc
conf="$conf
cbOkC.tooltip = ${tV%%|*}
"
fi;
fi;
fi;
fi;
fi;
beep
pashua_run "$conf" "$PA_userBase"
# beep
# "$CD" ok-msgbox --icon-file "$cautionICON" \
# --text "$1" --informative-text "$2" "$3"
}
function beep {
/usr/bin/osascript << EOT
tell application "Finder"
beep
end tell
EOT
}
# ========================================================
# PDbubble # Written by atErik, to use Pashua (instead of CocoaDialog)
# $1 "title text"
# $2 "message or informative text"
# $3 "icon/image path"
# $4 "autoCloseTime" is interger-numbers as seconds, or "-" for no-autoCloseTime
# when "-" is specified as $4 then "Ok"-button will be shown
# $5 "tooltip_image" msg : shows this msg when UI-pointer hovers/moves over the image shown in bubble-msg box,
# or specify "tooltip_image|tooltip_text|tooltip_okButton", or specify "-" or "-|-|-" to show no-tooltip
# $6 "bm1"/"bm2"/... indicating dialog/bubble-message box at different positions,
# (and textbox inside "bmN" msgbox can have different size & position)
# Use differnet numbered "bmN" bubble/dialog msg box, so that msgbox is shown without overlapping,
# or specify "bm1|bm1_x_position|bm1_y_position|text_height|text_width||text_x_position|text_y_position"
# ========================================================
function PDbubble { # Written by atErik, to use Pashua (instead of CocoaDialog)
# NOTES: The GUI elements are displayed in the order in which they appear in the config string.
# The only exception to this rule are buttons: the default button is always in the lower right
# corner of the window, the cancel button (if defined) is located left to the default button
# and any other buttons will appear in the lower left corner, from left to right, in the order
# they were defined.
local tV=""
local conf="
# Set window title
*.title = $1
# show an image
imgBbl.type = image
imgBbl.x = 50
imgBbl.y = 50
imgBbl.maxwidth = 64
imgBbl.path = $3
# Introductory text
txtBbl.type = text
txtBbl.default = $2
"
if [ ! -z $4 ] ; then
# $4 is either "-" or "integer-NUMBER"
if [ "$4" != "-" ] ; then
conf="$conf
# add a auto close timeout in seconds, for this shown dialog/bubble/msg box
*.autoclosetime = $4
"
else
if [ "$4" == "-" ] ; then
conf="$conf
# Show an “Ok” general-button at default-position
BokBbl.type = button
BokBbl.label = Ok
"
# we will not specify okb.x or okb.y in above,
# so that macOSX can place this general-button at-default position, left-bottom corner
fi;
fi;
fi;
if [ ! -z $5 ] ; then
if [ "$5 " != " " ] ; then
# "tooltip_image|tooltip_text|tooltip_okButton" or "-" or "-|-|-"
if [ "$5" != "-" ] && [ "$5" != "-|-|-" ] ; then
if [ "${5%%|*}" != "-" ] ; then
# tooltip msg for image
conf="$conf
imgBbl.tooltip = ${5%%|*}
"
fi;
tV=${5#*|}
if [ "${tV%%|*}" != "-" ] ; then
# tooltip msg for text
conf="$conf
txtBbl.tooltip = ${tV%%|*}
"
fi;
if [ "$4" == "-" ] ; then
tV=${tV#*|}
if [ "${tV%%|*}" != "-" ] ; then
# tooltip msg for a button showing “Ok”
conf="$conf
BokBbl.tooltip = ${tV%%|*}
"
fi;
fi;
fi;
fi;
fi;
tV=""
if [ ! -z $6 ] ; then
# "bm1|bm1_x_position|bm1_y_position|text_height|text_width||text_x_position|text_y_position"
if [ "${6:3:1}" == "|" ] ; then
tV="${6:4}"
conf="$conf
# bmN dialog msg box's vertical x position
*.x = ${tV%%|*}
"
tV=${tV#*|}
conf="$conf
# bmN dialog msg box's horizontal y position
*.y = ${tV%%|*}
"
tV=${tV#*|}
conf="$conf
# height of text box/area inside bmN msgbox
txtBbl.height = ${tV%%|*}
"
tV=${tV#*|}
conf="$conf
# width of text box/area inside bmN msgbox
txtBbl.width = ${tV%%|*}
"
tV=${tV#*|}
conf="$conf
# vertical x position of text box/area inside bmN msgbox
txtBbl.x = ${tV%%|*}
"
tV=${tV#*|}
conf="$conf
# horizontal y position of text box/area inside bmN msgbox
txtBbl.y = ${tV%%|*}
"
else
conf="$conf
# vertical & horizontal position of text box inside bubble/dialog msg box
txtBbl.x = 50
txtBbl.y = 120
# height & width of text box inside bubble/dialog msg box
txtBbl.height = 100
txtBbl.width = 310
"
case "${6:0:3}" in
('bm1') # adding a fixed/specific vertical & horizontal position, to show the “bm1” bubble/dialog msg box
conf="$conf
# vertical & horizontal position of “bm1” bubble/dialog msg box
*.x = 50
*.y = 400
"
;;
('bm2') # adding a fixed/specific vertical & horizontal position, to show the “bm2” bubble/dialog msg box
conf="$conf
# vertical & horizontal position of “bm2” bubble/dialog msg box
*.x = 200
*.y = 400
"
;;
('bm3') # adding a fixed/specific vertical & horizontal position, to show the “bm3” bubble/dialog msg box
conf="$conf
# vertical & horizontal position of “bm3” bubble/dialog msg box
*.x = 350
*.y = 400
"
;;
('bm4') # adding a fixed/specific vertical & horizontal position, to show the “bm4” bubble/dialog msg box
conf="$conf
# vertical & horizontal position of “bm4” bubble/dialog msg box
*.x = 500
*.y = 400
"
;;
esac;
fi;
else
conf="$conf
# vertical & horizontal position of text box inside bubble/dialog msg box
txtBbl.x = 50
txtBbl.y = 120
# height & width of text box inside bubble/dialog msg box
txtBbl.height = 100
txtBbl.width = 310
"
# We are not adding *.x & *.y in above,
# so that MacOS can show this bubble/dialog msg box in its default position
fi;
beep
pashua_run "$conf" "$PA_userBase"
}
# ========================================================
# PDfileOrDirSelect # Written by atErik, to use Pashua (instead of CocoaDialog)
# $1 "title text"
# $2 "label or informative text"
# $3 "dirOrFileLocation" = path/directoryOrFile location
# $4 "fileTypeExtension or directory" = if its "directory" then only "directory" selection is allowed,
# if its filetypes (i.e: "jpg gif") then that/those fileType(s) selection is/are allowed
# $5 optional "tooltip_img|tooltip_txt|tooltip_fileBrowser|tooltip_okButton|tooltip_cancelButton"
# or specify "-" to show no-tooltip
# ========================================================
function PDfileOrDirSelect { # Written by atErik, to use Pashua (instead of CocoaDialog)
local tV=""
local conf="
# Set window title
*.title = $1
# show an image
imgSlct.type = image
imgSlct.x = 50
imgSlct.y = 50
imgSlct.maxwidth = 64
imgSlct.path = $appICON
# Introductory text
txtSlct.type = text
txtSlct.default = $2
txtSlct.height = 100
txtSlct.width = 310
txtSlct.x = 50
txtSlct.y = 120
# Add a filesystem browser (openFileOrDirBrowser)
SlctFB.type = openbrowser
SlctFB.label = $2
# SlctFB.label = Example filesystem browser (textfield + open panel)
SlctFB.width=380
SlctFB.height=350
SlctFB.default = $3
SlctFB.x = 180
SlctFB.y = 50
# Add a “Cancel” button with default-label & show at default-positon
SlctCB.type = cancelbutton
# Show an “Ok” general-button at default-position
SlctOkB.type = button
SlctOkB.label = Ok
"
# we will not specify SlctOkB.x or SlctOkB.y in above,
# so that macOSX can place this general-button at-default position, left-bottom corner
# Setting by-default mode, to select "directory"-only:
if [ ! -z $4 ] ; then
if [ "$4" != "directory" ] ; then
conf="$conf
# user-specified fileTypes selection is allowed
SlctFB.filetype = $4
"
else
conf="$conf
# only-directory selection is allowed
SlctFB.filetype = directory
"
fi;
else
conf="$conf
# only-directory selection is allowed
SlctFB.filetype = directory
"
fi;
if [ ! -z $5 ] ; then
if [ "$5 " != " " ] ; then
if [ "${5%%|*}" != "-" ] ; then
# tooltip msg for img
conf="$conf
imgSlct.tooltip = ${5%%|*}
"
fi;
tV=${5#*|}
if [ "${tV%%|*}" != "-" ] ; then
# tooltip msg for text
conf="$conf
txtSlct.tooltip = ${tV%%|*}
"
fi;
tV=${tV#*|}
if [ "${tV%%|*}" != "-" ] ; then
# tooltip msg for openFileOrDirBrowser
conf="$conf
SlctFB.tooltip = ${tV%%|*}
"
fi;
tV=${tV#*|}
if [ "${tV%%|*}" != "-" ] ; then
# tooltip msg for a button showing “Ok”
conf="$conf
SlctOkB.tooltip = ${tV%%|*}
"
fi;
tV=${tV#*|}
if [ "${tV%%|*}" != "-" ] ; then
# tooltip msg for a button showing “Cancel”/etc
conf="$conf
SlctCB.tooltip = ${tV%%|*}
"
fi;
fi;
fi;
beep
pashua_run "$conf" "$PA_userBase"
}
# ========================================================
# PDmultiButtons # Written by atErik, to use Pashua (instead of CocoaDialog)
# $1 "title text"
# $2 "label or informative text"
# $3 "app icon/image path" = path/directory location
# $4 "buttonN_Show_Text" : when 4th & next items begin with "button1_", "button2_", etc, THEN
# : text-specified after the 1st "_" will be displayed in the shown-button
# : other-than 1st "_", all other "_" will be converted into "space" symbol
# ========================================================
function PDmultiButtons { # Written by atErik, to use Pashua (instead of CocoaDialog)
local tV=""
local conf="
# Set window title
*.title = $1
# show an image
imgMB.type = image
imgMB.x = 50
imgMB.y = 50
imgMB.maxwidth = 64
imgMB.tooltip = This is an element of type “image”
imgMB.path = $appICON
# Introductory text
txtMB.type = text
txtMB.default = $2
txtMB.height = 180
txtMB.width = 310
txtMB.x = 50
txtMB.y = 120
txtMB.tooltip = This is an element of type “text”
"
if [ ! -z $4 ] ; then
if [ "${4:0:8}" == "button1_" ] ; then
tV="${4:8}"; # get all text after the 1st-underscore symbol
tV=${tV//_/ }; # change all "underscore" into "space" character/symbol
conf="$conf
# add a button with user-specified text
gb1MB.type = button
gb1MB.label = $tV
gb1MB.x = 260
gb1MB.y = 50
"
fi
fi;
if [ ! -z $5 ] ; then
if [ "${5:0:8}" == "button2_" ] ; then
tV="${5:8}"
tV=${tV//_/ }
conf="$conf
# add another button with user-specified text
gb2MB.type = button
gb2MB.label = $tV
gb2MB.x = 260
gb2MB.y = 140
"
fi
fi;
if [ ! -z $6 ] ; then
if [ "${6:0:8}" == "button3_" ] ; then
tV="${6:8}"
tV=${tV//_/ }
# "Configuration error: Element “gb3” lacks a type attribute. In other words: you have to add a line like the following one: gb3.type = textfield"
conf="$conf
# add another button with user-specified text
gb3MB.type = button
gb3MB.label = $tV
gb3MB.x = 260
gb3MB.y = 240
"
fi
fi;
if [ ! -z $7 ] ; then
if [ "${7:0:8}" == "button4_" ] ; then
tV="${7:8}"
tV=${tV//_/ }
conf="$conf
# add another button with user-specified text, in another row, under the previous 3-buttons
gb4MB.type = button
gb4MB.label = $tV
gb4MB.x = 300
gb4MB.y = 50
"
fi
fi;
beep
pashua_run "$conf" "$PA_userBase"
}
# ========================================================
# PDprogressBarDirsFilesCpOrMv # Written by atErik, to use Pashua (instead of CocoaDialog)
# $1 "Operation | title text" : Operation can be "Copy" or "Move" : either Copy or Move operation
# "title text" part is for displaying given text on title of the shown dialog box
# $2 "Source Folder/File"
# $3 "Destination Folder/File"
# $4 "Elapsed_Time | Refresh_Time" : Files+Dirs ReCounting Event Occurred How Many Seconds After Beginning
# "RefreshTime" is indicating the time after which current dialog box is removed, & new updated is shown
# $5 "extra info 1" : Multi Lines are separated by "|" symbol , use "-" to keep it empty
# $6 "extra info 2" : use "-" to keep it empty
# $7...$9 : format: "ProgressBAR/PERCENT_NUMBER|nominatorNumber|denominatorNumber"
# $7 is for Files, $8 is for Directories, $9 is for Size
# ========================================================
function PDprogressBarDirsFilesCpOrMv {
local tV="" Src="" Dest="" oped="copied" tymP=""
local cp=1 tymPsd=0 p1=0 p1n=0 p1d=0 p2=0 p2n=0 p2d=0 p3=0 p3n=0 p3d=0
local L1="" L2="" L3="" L4="" L5="" L6="" L7="" L8="" L9=""
local conf=""
# local CpOrMv=""
if [ ! -z $1 ] ; then
tV=${1%%|*}
if [ "$tV" == "Move" ]; then
# CpOrMv="mv"
cp=0
#elif [ "$tV" == "Copy" ]; then
# CpOrMv="cp -R"
fi
conf="
# Set window title
*.title = ${1#*|}
"
fi
if [ ! -z $2 ] ; then
Src=$2
fi
if [ ! -z $3 ] ; then
Dest=$3
fi
if [ ! -z $4 ] ; then
# Getting Elapsed Time:
tymPsd=${4%%|*}
# Getting Refresh Time:
# adding Auto-Closing TIMEOUT in seconds for this dialog/progress/bar/info msg box
conf="$conf
# auto close this dialog box after this second(s)
*.autoclosetime = ${4#*|}
"
fi
if [ ! -z $7 ] ; then
# 1ST "ProgressBarNUMBER|nominator|denominator" for FILES
# "progressBarNUMBER|CopiedNumberOrAmount|TotalNumberOrAmount"
tV="${7#*|}"
p1n=${tV%%|*}
tV=${tV#*|}
p1d=${tV%%|*}
# Calculating the PERCENT-NUMBER for What % amount of FILES are so far Copied:
# p1=$((200*$p1n/$p1d % 2 + 100*$p1n/$p1d))
p1=$(( ($p1n*1000/$p1d+5)/10 ))
fi;
if [ ! -z $8 ] ; then
# 2ND "ProgressBarNUMBER|nominator|denominator" for DIRECTORIES
# "progressBarNUMBER|CopiedNumberOrAmount|TotalNumberOrAmount"
tV="${8#*|}"
p2n=${tV%%|*}
tV=${tV#*|}
p2d=${tV%%|*}
# Calculating the PERCENT-NUMBER for What % amount of DIRECTORIES/FOLDERS are so far Copied:
# p2=$((200*$p2n/$p2d % 2 + 100*$p2n/$p2d))
p2=$(( ($p2n*1000/$p2d+5)/10 ))
fi;
if [ ! -z $9 ] ; then
# 3RD "ProgressBarNUMBER|nominator|denominator" for SIZE
# "progressBarNUMBER|CopiedNumberOrAmount|TotalNumberOrAmount"
tV="${9#*|}"
p3n=${tV%%|*}
tV=${tV#*|}
p3d=${tV%%|*}
# Calculating the PERCENT-NUMBER for What % amount of DATA-SIZE/MegaBYTES are so far Copied:
# p3=$((200*$p3n/$p3d % 2 + 100*$p3n/$p3d))
# p3=$(( ($p3n*1000/$p3d+5)/10 ))
# We will add PERCENTAGE for FILES & DIRS SIZE, later
# p3=0
fi;
# PERCENT-AMOUNT CAN BE CONVERTED INTO A TEXT-BASED PROGRESS BAR SHOWN ON GUI DIALOG BOX EASILY,
# we will improve it later, now lets focus on core/important functions, stability, security of other codes
if [ "$cp" -eq 0 ] ; then
oped="moved"
fi;
if [ "$tymPsd" -gt 60 ] ; then
tymP="$(( $tymPsd / 60 )) minute(s) & $(( $tymPsd % 60 )) second(s)"
else
tymP="$tymPsd second(s)"
fi;
# Later, PERCENT % will be shown as a [****** ] based ProgressBar on this Pashua GUI dialog box
L1="${1}ing...[return]"
L2="From: \"$Src\"[return]"
L3="To: \"$Dest\"[return]"
L4="Total $p1d files & $p2d directories ( $pfCTS )[return]"
L5="So far $oped: ${p1}% : $p1n file(s)[return]"
L6="So far $oped: ${p2}% : $p2n directory(s)[return]"
L7="So far $oped: Total Size calculation for Files & Dirs is now off[return]"
L8="Time Elapsed/Passed since $1 started: $tymP[return]"
L9="Info will be updated after ${4#*|}-seconds, so PLEASE WAIT..."
# Adding text box(es) to show all info:
conf="
# Introductory text
txt1Prgrs.type = text
txt1Prgrs.height = 180
txt1Prgrs.width = 500
txt1Prgrs.x = 35
txt1Prgrs.y = 200
txt1Prgrs.default = ${L1}${L2}${L3}${L4}${L5}${L6}${L7}${L8}${L9}
"
# txt2Prgrs.type = text
# txt3Prgrs.type = text
# txt4Prgrs.type = text
pashua_run "$conf" "$PA_userBase"
}
# ========================================================
# bsd_command_check
# Check that the required BSD command are installed
# ========================================================
function command_check_msg { # Modified by atErik : adding 'local'
local message1="One or more *BSD commands* to run Portable $appID were not found on \
this machine. You must install the BSD Subsystem package that is in the \
following folder on disk 1 of your Mac OS X installation DVD:\n/Welcome to Mac \
OS X/Optional Installs.\n\nNow quit."
local button="` /usr/bin/osascript << EOT
tell application "Finder"
beep
display dialog "$message1" buttons {"Quit"} \
with icon caution default button "Quit"
set result to button returned of result
end tell
EOT `"
if test "$button" == "Quit"; then # Quit application
exit 112
fi
}
function bsd_command_check { # written by Patrick Luby # Modified by atErik : adding 'local',
# Modified to add : wait df du cut tail find wc dirname readlink
local commands="awk cp defaults diskutil echo grep ln mkfifo mkdir mv plutil ps rm sed sleep touch wait df du cut tail find wc dirname readlink"
for i in $commands ; do
if [ ! -x "/usr/bin/$i" -a ! -x "/bin/$i" -a ! -x "/usr/sbin/$i" -a ! -x "/sbin/$i" ] ; then
# Return 96 + 16 if a command is not found
command_check_msg;
exit 112;
fi
done
}
# ========================================================
# osx_version_check
# Check that the user is running Mac OS X 10.4 or higher
# ========================================================
function version_check_msg { # Modified by atErik : adding 'local'
local message1="You are running OS X version $version.\n\
Portable $appID can only be opened on Mac OS X 10.4 or higher."
local button="` /usr/bin/osascript << EOT
tell application "Finder"
beep
display dialog "$message1" buttons {"Quit"} \
with icon caution default button "Quit"
set result to button returned of result
end tell
EOT `"
if test "$button" == "Quit"; then # Quit application
exit 113
fi
}
function osx_version_check { # written by Patrick Luby # Modified by atErik : adding 'local'
local version="";
if [ -x "/usr/bin/sw_vers" ] ; then
# Return 96 + 17 if it is a bad version
version=`/usr/bin/sw_vers | grep '^ProductVersion:' | awk '{ print $2 }'`
case "$version" in
10.[0123]) version_check_msg ; exit 113;;
10.[0123].*) version_check_msg ; exit 113;;
esac
fi
}
# ========================================================
# quitApp
# Check if local app is open and quit
# ========================================================
function quitApp { # Modified by atErik : adding 'local'
local rv=0;
if ps cx | grep '[0-9] '"$appBin"'$' > /dev/null; then
rv=` CDokMsg "$appID is already running on this system" \
"Only one copy can be run at a time. \
Quit runnig $appID and reopen Portable $appID." "--no-cancel" `
if [ "$rv" == "1" ] ; then # Quit application
exit 0
fi
fi
}
# ========================================================
# check_p_asf
# Check and create Portable Application Support folders
# ========================================================
function check_p_asf { # Modified by atErik : adding 'local'
# "Read Only" string in till OsX 10.5
local readonly5=`diskutil info "$PA_userBase" | grep "Read Only" | awk '{ print $3 }'`
# "Read-Only Volume:" string on OsX 10.6
local readonly6=`diskutil info "$PA_userBase" | grep "Read-Only Volume" | awk '{ print $3 }'`
if [ "$readonly5" = Yes ] || [ "$readonly6" = Yes ]; then
CDokMsgC "Portable $appID is on a locked volume" "Portable $appID can't \
be opened on a locked volume. Now quit." "--no-cancel" > /dev/null
exit 0
else
if [ ! -d "$PA_userPref" ] ; then
mkdir -p "$PA_userPref"
fi
fi
}
# ========================================================
# copy_local_pref
# Copy local preferences to Portable Application
# ========================================================
function select_profile { # Modified by atErik : adding 'local', "chosen", PDfileOrDirSelect
local rv=0;
rvpf=` PDfileOrDirSelect "Select local $appID Profile folder" \
"Look for a folder named \"********.default\" or similar." \
"$userPrefBase" "directory" `
# rvpf=` "$CD" fileselect --title "Select local $appID Profile folder" \