forked from DonovanChan/applescripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpasteClip.applescript
More file actions
133 lines (117 loc) · 4.31 KB
/
pasteClip.applescript
File metadata and controls
133 lines (117 loc) · 4.31 KB
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
(*
NAME: PasteClip
VERSION: 1.0
PURPOSE: Pastes FileMaker object into active FileMaker file using object from defined file alias
HISTORY:
Created 2010.06.30 by Donovan Chandler, donovan_c@beezwax.net
Modified 2012.04.03 by Donovan Chandler: Added support for XML2 format (in FM 12)
NOTES:
*)
------------------------------------------------
---- Settings ----
-- Placeholder, replaced with calculated date
set strDatePlaceholder to "%DATE%"
-- Alias to XML file containting FileMaker clip
-- e.g., "Macintosh HD:Users:Me:Desktop:myClip.xml"
--set clipAlias to "" as alias
-- Alternative alias
-- File in ../Clips
-- Disable if clip path specified above
if true then
set clipName to "scriptHeaderSteps.xml"
set clipDir to POSIX file (POSIX path of (path to me) & "/..") as text
set clipAlias to (clipDir & "Clips:" & clipName) as alias
end if
-- Format of FileMaker object in clip [script|script_step|table|field|custom_function]
set clipClass to "script_step"
-- Paste clip in automatically?
-- Not yet supported
set autoPasteClip to false
------------------------------------------------
---- Format Date ----
set strDateFull to do shell script "date '+%Y-%h-%d %Hh%M'"
---- Edit Clip ----
set clipText to readFile(clipAlias)
set clipTextNew to searchReplaceText(clipText, strDatePlaceholder, strDateFull)
---- Convert clip XMSC ----
set clipTextFormatted to convertClip(clipTextNew, clipClass)
---- Insert Clip ----
set the clipboard to clipTextFormatted
if autoPasteClip is true then paste()
------------------------------------------------
-- HANDLERS
------------------------------------------------
-- Handler: Performs paste
on paste()
tell application "System Events" to keystroke "v" using {command down}
end paste
-- Handler: Searches and replaces string within text block
to searchReplaceText(theText, searchString, replaceString)
set searchString to searchString as list
set replaceString to replaceString as list
set theText to theText as text
set oldTID to AppleScript's text item delimiters
repeat with i from 1 to count searchString
set AppleScript's text item delimiters to searchString's item i
set theText to theText's text items
set AppleScript's text item delimiters to replaceString's item i
set theText to theText as text
end repeat
set AppleScript's text item delimiters to oldTID
return theText
end searchReplaceText
-- Handler: Returns text from file. Prompts for file if no alias specified.
on readFile(fileAlias)
if fileAlias = "" then
set theFile to choose file with prompt (localized string "chooseFile")
else
set theFile to fileAlias
end if
try
open for access theFile
set fileText to (read theFile)
close access theFile
return fileText
on error errMsg number errNum
try
close access theFile
end try
display dialog errMsg & return & errNum
end try
end readFile
-- HANDLER: Converts xml text to FileMaker clipboard format
-- Parameters: clipText, outputClass [script|script_step|table|field|custom_function]
-- Methodology: Write text to temp file so that it can be converted from file
-- Formats:
-- XMSC for script definitions
-- XMSS for script steps
-- XMTB for table definitions
-- XMFD for field definitions
-- XMCF for custom functions
-- XML2 for layout objects in FileMaker 12
-- XMLO for layout objects in FileMaker 7-11
on convertClip(clipText, outputClass)
set temp_path to (path to temporary items as Unicode text) & "FMClip.dat"
set temp_ref to open for access file temp_path with write permission
set eof temp_ref to 0
write clipText to temp_ref as «class utf8»
close access temp_ref
if outputClass is "XMSC" then
set clipTextFormatted to read file temp_path as «class XMSC»
else if outputClass is "XMSS" then
set clipTextFormatted to read file temp_path as «class XMSS»
else if outputClass is "XMTB" then
set clipTextFormatted to read file temp_path as «class XMTB»
else if outputClass is "XMFD" then
set clipTextFormatted to read file temp_path as «class XMFD»
else if outputClass is "XMFN" then
set clipTextFormatted to read file temp_path as «class XMFN»
else if outputClass is "XML2" then
set clipTextFormatted to read file temp_path as «class XML2»
else if outputClass is "XMLO" then
set clipTextFormatted to read file temp_path as «class XMLO»
else
return "Error: Snippet class not recognized"
end if
return clipTextFormatted
end convertClip