-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmbt.applescript
119 lines (104 loc) · 3.41 KB
/
smbt.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
-- Handler that writes text to a file
on writeTextToFile(theText, theFile, overwriteExistingContent)
try
-- Convert the file to a string
set theFile to theFile as string
-- Open the file for writing
set theOpenedFile to open for access file theFile with write permission
-- Clear the file if content should be overwritten
if overwriteExistingContent is true then set eof of theOpenedFile to 0
-- Write the new content to the file
write theText to theOpenedFile
-- Close the file
close access theOpenedFile
-- Return a boolean indicating that writing was successful
return true
-- Handle a write error
on error
-- Close the file
try
close access file theFile
end try
-- Return a boolean indicating that writing failed
return false
end try
end writeTextToFile
-- Handler taht converts a list to string
on convertListToString(theList, theDelimiter)
set AppleScript's text item delimiters to theDelimiter
set theString to theList as string
set AppleScript's text item delimiters to ""
return theString
end convertListToString
-- Handler that gets the position of an item in the list
on getPositionOfItemInList(theItem, theList)
repeat with a from 1 to count of theList
if item a of theList is theItem then return a
end repeat
return 0
end getPositionOfItemInList
-- Handler that converts a path to an a POSIX path string
on convertPathToPOSIXString(thePath)
tell application "System Events"
try
set thePath to path of disk item (thePath as string)
on error
set thePath to path of thePath
end try
end tell
return POSIX path of thePath
end convertPathToPOSIXString
-- convertPathToPOSIXString(POSIX file ("/Users/vaibhavthakkar"))
property safariPath : "[PROVIDE_THE_PATH_HERE_FOR_SAFARI_TABS]"
property chromePath : "[PROVIDE_THE_PATH_HERE_FOR_CHROME_TABS]"
-- Main running handler
on run argv
set LF to character id 10
set browser_list to {"Safari", "Google Chrome"}
set all_url_list to {}
set paths_list to {safariPath, chromePath}
if length of argv is 0 then
log "No browser name given"
else if browser_list does not contain argv then
log "Wrong Browser Name"
else
set browserName to item 1 of argv
set folderName to item (getPositionOfItemInList(browserName, browser_list)) of paths_list
if browserName is "Safari" then
tell application "Safari"
activate
repeat with thisWind in (get windows)
local url_list
set url_list to {}
repeat with t in (tabs of thisWind)
set TabTitle to (name of t)
set TabURL to (URL of t)
set TabInfo to ("" & TabTitle & return & TabURL & return)
copy TabInfo to the end of url_list
end repeat
copy url_list to the end of all_url_list
end repeat
end tell
else if browserName is "Google Chrome" then
tell application "Google Chrome"
activate
repeat with thisWind in (get windows)
local url_list
set url_list to {}
repeat with t in (tabs of thisWind)
set TabTitle to (title of t)
set TabURL to (URL of t)
set TabInfo to (TabTitle & LF & TabURL & LF)
copy TabInfo to the end of url_list
end repeat
copy url_list to the end of all_url_list
end repeat
end tell
end if
repeat with a from 1 to length of all_url_list
set currList to item a of all_url_list
set resultText to convertListToString(currList, LF)
writeTextToFile(resultText, folderName & a & ".txt", true)
end repeat
end if
end run