forked from DonovanChan/fmfunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppleScriptFilePathsInDir.calc
79 lines (74 loc) · 2.6 KB
/
AppleScriptFilePathsInDir.calc
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
Let ( [
path = Get ( FilePath )
; dbName = Middle ( path ; Position ( path ; "/" ; Length ( path ) ; -1 ) + 1 ; 999 )
; fieldSplit = Substitute ( resultFieldName ; "::" ; ¶ )
; tableName = GetValue ( fieldSplit ; 1 )
; fieldName = GetValue ( fieldSplit ; 2 )
; fmpVersion =
Case (
PatternCount ( Get ( ApplicationVersion ) ; "ProAdvanced" )
; "FileMaker Pro Advanced"
; "FileMaker Pro"
)
; dirPath = GetValue ( dirPath ; 1 )
] ;
"set dirPath to " & Quote ( dirPath ) & "¶
set dirPath to stripStartupDisk(dirPath)¶
tell application \"Finder\"¶
set dirAlias to (POSIX file dirPath) as alias¶
set theItems to every file of folder dirAlias¶
set filePaths to my fileListToText(theItems, true)¶
end tell¶
setField(\"" & dbName & "\", \"" & tableName & "\", \"" & fieldName & "\", filePaths)¶
¶
-- Handler: Returns list of files as return-delimited text string¶
-- addStartupDrive allows prepending of disk name to each path¶
to fileListToText(theList, addStartupDrive)¶
set theText to \"\"¶
tell application \"Finder\"¶
set hdName to get name of startup disk¶
end tell¶
repeat with i in theList¶
set myPath to POSIX path of (i as alias)¶
if addStartupDrive is true then set myPath to hdName & (myPath as text)¶
set theText to theText & myPath & return¶
end repeat¶
return theText¶
end fileListToText¶
¶
--Handler: Sets FileMaker field value¶
on setField(databaseName, tableName, fieldName, theValue)¶
tell application \"" & fmpVersion & "\"¶
tell database (databaseName as text)¶
tell table (tableName as text)¶
set field fieldName to theValue¶
end tell¶
end tell¶
end tell¶
end setField¶
¶
-- Handler: Returns path as text with startup disk removed¶
to stripStartupDisk(thePath)¶
set pathText to thePath as text¶
tell application \"Finder\"¶
set hdName to name of startup disk¶
end tell¶
set hdLen to length of hdName¶
set colonPos to offset of \":\" in pathText¶
if colonPos is greater than 0 then set pathText to text (colonPos + 1) thru -1 of pathText¶
if character 1 of pathText is equal to \"/\" then set pathText to text 2 thru -1 of pathText¶
if text 1 thru hdLen of pathText is equal to hdName then¶
set pathText to text (hdLen + 1) thru -1 of pathText¶
end if¶
return pathText¶
end stripStartupDisk"
)
/* —————————————————————————————— //
NAME:
AppleScriptFilePathsInDir ( resultFieldName ; dirPath )
PURPOSE:
Returns path of each file in first level of directory (as return-delimited list)
EXAMPLES:
HISTORY:
Created: 2012-Jan-19 20h16 PST — Donovan Chandler
*/