forked from FreeFem/FreeFem-sources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FreeFem++.scrpt-txt.in
68 lines (58 loc) · 1.59 KB
/
FreeFem++.scrpt-txt.in
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
# Author F. hecht with the help of Vincent Bernardi
# this is a free software with no garanty at all.
#---------------
# take from the web (thank to Alec Web log).
# http://www.alecjacobson.com/weblog/
on last_offset(the_text, char)
try
set len to count of the_text
set reversed to reverse of characters of the_text as string
set last_occurrence to len - (offset of char in reversed) + 1
if last_occurrence > len then
return 0
end if
on error
return 0
end try
return last_occurrence
end last_offset
on dirname(the_path)
set last_occurrence to last_offset(the_path, "/")
if last_occurrence is equal to 0 then
return "."
end if
if last_occurrence is equal to 1 then
return "/"
end if
if last_occurrence is equal to (count of the_path) then
set the_path to items 1 thru (last_occurrence - 1) of the_path as string
return dirname(the_path)
end if
return items 1 thru (last_occurrence - 1) of the_path as string
end dirname
# end of web part ...
# the freefem++ action
# -------------------
on freefem(edpfile)
set edppath to POSIX path of edpfile
set edpdir to dirname(edppath)
tell application "Terminal"
activate
try
do shell script "/bin/bash -c 'export PATH=\"PATH:@bindir@\";cd \"" & edpdir & "\";FreeFem++ \"" & edppath & "\"'"
end try
end tell
end freefem
# to do on drag and drop
# -------------------
on open filelist
repeat with edpfile in filelist
freefem(edpfile)
end repeat
return
end open
# other default case ….
# -------------------
set edpfile to choose file with prompt "Choose a edp script:"
freefem(edpfile)