forked from DonovanChan/fmfunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppleScriptFilePathsInDirPrompt.calc
89 lines (83 loc) · 3.11 KB
/
AppleScriptFilePathsInDirPrompt.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
80
81
82
83
84
85
86
87
88
89
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"
) ;
message = If ( IsEmpty ( message ) ; "Please select a folder." ; message ) ;
defaultDirPath = GetValue ( defaultDirPath ; 1 ) ;
showInvisibles = (showInvisibles = True) ;
multipleSelection = (multipleSelection = True)
];
"set myFolder to {}¶
set myFolder to myFolder & choose folder with prompt \"" & message & "\" ¦" &
If ( not IsEmpty ( defaultDirPath ) ;
"default location POSIX file stripStartupDisk(\"" & defaultDirPath & "\") ¦"
) &
"invisibles " & showInvisibles & " ¦
multiple selections allowed " & multipleSelection & ¶ &
"tell application \"Finder\"¶
set theItems to {}¶
repeat with dir in myFolder¶
set theItems to theItems & every file of folder dir¶
end repeat¶
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 ; message ; defaultDirPath ; showInvisibles ; multipleSelection )
PURPOSE:
Prompts user for directory and returns paths of each file in first level of directory (as return-delimited list)
EXAMPLES:
HISTORY:
Created: 2011-Jun-21 17h49 PST — Donovan A. Chandler
*/