-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathTransmission.applescript
More file actions
77 lines (59 loc) · 2.17 KB
/
Copy pathTransmission.applescript
File metadata and controls
77 lines (59 loc) · 2.17 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
(*
Transmission Library
v1.0
Dov Frankel, 2013
property LibLoader : load script file ((path to scripts folder from user domain as text) & "Libraries:Library Loader.scpt")
property TransmissionLib : LibLoader's loadScript("Libraries:Transmission.applescript")
tell TransmissionLib to Initialize()
tell TransmissionLib to ToggleSpeedLimit(true)
tell TransmissionLib to Finalize()
*)
-- Remember if Transmission's Speed Limit was on before the script ran
global speedLimitWasPreviouslyOn
property toggleEnabledDelay : 15
property delayOn : true
-- Should be the first call a script that uses this library makes
on initialize()
set speedLimitWasPreviouslyOn to my SpeedLimitIsOn()
set delayOn to true
end initialize
-- Should be the last call a script that uses this library makes
on Finalize()
my ToggleSpeedLimit(speedLimitWasPreviouslyOn)
set delayOn to true
end Finalize
-- Used during testing to eliminate waiting. Turned back on in Finalize().
on TurnDelayOff()
set delayOn to false
end TurnDelayOff
-- Turns Speed Limit on or off, depending on the SpeedLimitOn parameter
on ToggleSpeedLimit(SpeedLimitOn)
if not my TransmissionIsRunning() then return
-- Sometimes necessary (who knows why)
set SpeedLimitOn to SpeedLimitOn as boolean
tell application "Transmission" to activate
tell application "System Events"
tell process "Transmission"
-- If the limit isn't already set to what it should be, toggle it
if SpeedLimitOn ≠ my SpeedLimitIsOn() then
click menu item "Speed Limit" of menu "Transfers" of menu bar 1
-- If it was just toggled on, wait for it to kick in before returning
if SpeedLimitOn and delayOn then
delay toggleEnabledDelay
end if
end if
end tell
end tell
end ToggleSpeedLimit
on SpeedLimitIsOn()
if not my TransmissionIsRunning() then return no
tell application "Transmission" to activate
tell application "System Events"
tell process "Transmission"
return (value of attribute "AXMenuItemMarkChar" of menu item "Speed Limit" of menu "Transfers" of menu bar 1 is not missing value)
end tell
end tell
end SpeedLimitIsOn
on TransmissionIsRunning()
return application "Transmission" is running
end TransmissionIsRunning