-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathURL_BrowserAppDelegate.applescript
153 lines (113 loc) · 4 KB
/
URL_BrowserAppDelegate.applescript
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
--
-- URL_BrowserAppDelegate.applescript
-- URL Browser
--
-- Created by Christian Sonntag on 18.06.10.
-- Copyright 2010 __MyCompanyName__. All rights reserved.
--
script URL_BrowserAppDelegate
property parent : class "NSObject"
-- outlets
property theUrlDisplay : missing value
property rangeLabel : missing value
property ACHelpers : missing value
property filePathControl : missing value
--misc
property tempUrl : missing value
property theLoc : missing value
property theLen : missing value
property valfldr : missing value
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
on awakeFromNib()
ACHelpers's selectTextInTextfield_(theUrlDisplay)
end awakeFromNib
--get the url out of safari
on getUrlOfSafari_(sender)
tell application "Safari"
set theUrl to URL of document 1
end tell
theUrlDisplay's setStringValue_(theUrl)
set tempUrl to theUrl
end getUrlOfSafari_
--get selected textrange of textfield
on getNSTextFieldRangeValue_(sender)
set {theLoc, theLen} to ACHelpers's rangeOfTextFieldSelection_(theUrlDisplay) as list
end getNSTextFieldRangeValue_
--display status text in NSLabel
on setNSTextFieldValue_(sender)
theUrlDisplay's setStringValue_(tempUrl)
end setNSTextFieldValue_
on displayRange_(sender)
# Returns an array which you can retrieve the values as a list
if theLoc is not 0 and theLen is not 0 then
rangeLabel's setStringValue_("Textrange: " & (theLoc as text) & " | " & (theLen as text))
else
beep
end if
end displayRange_
on upUrl_(sender)
my getNSTextFieldRangeValue_(me)
if theLoc is not 0 and theLen is not 0 then
set prefix to (characters 1 thru theLoc of tempUrl) as string
set counter to ((characters (theLoc + 1) thru (theLoc + theLen) of tempUrl) as string) as integer
set sufix to (characters (theLoc + 1 + theLen) thru (count of tempUrl) of tempUrl) as string
set counter to counter + 1
tell application "Safari"
set URL of document 1 to prefix & counter & sufix
activate
end tell
set tempUrl to prefix & counter & sufix
my setNSTextFieldValue_(me)
my displayRange_(me)
else
beep
end if
end upUrl_
on downUrl_(sender)
my getNSTextFieldRangeValue_(me)
if theLoc is not 0 and theLen is not 0 then
set prefix to (characters 1 thru theLoc of tempUrl) as string
set counter to ((characters (theLoc + 1) thru (theLoc + theLen) of tempUrl) as string) as integer
set sufix to (characters (theLoc + 1 + theLen) thru (count of tempUrl) of tempUrl) as string
set counter to counter - 1
tell application "Safari"
set URL of document 1 to prefix & counter & sufix
activate
end tell
set tempUrl to prefix & counter & sufix
my setNSTextFieldValue_(me)
my displayRange_(me)
else
beep
end if
end downUrl_
on saveDocument_(sender)
tell application "Safari"
set docUrl to URL of document 1
end tell
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set urlArray to text items of docUrl
set AppleScript's text item delimiters to oldDelims
tell application "Safari"
save document 1 in valfldr & "/" & last item of urlArray
end tell
end saveDocument_
on historyBack_(sender)
tell application "Safari"
do JavaScript "history.back()" in document 1
activate
end tell
end historyBack_
on subchoosefolder_(sender)
set valfldr to text 1 thru -2 of ((choose folder with prompt "Choose the default location for the choose file." with showing package contents) as alias as string) --Prevent an extra / on the end.
filePathControl's |setURL_|(POSIX path of valfldr)
set valfldr to POSIX path of valfldr
end subchoosefolder_
end script