forked from a4agarwal/dropzone-user-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSend_to_iPhone.dropzone
executable file
·127 lines (106 loc) · 3.67 KB
/
Send_to_iPhone.dropzone
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
#!/usr/bin/ruby
# encoding: utf-8
# myPhoneDesktop for Dropzone extension
# v1.0, 02/01/2012
# Author: jProductivity
# Copyright © 2012 jProductivity, LLC
# http://www.myphonedesktop.com/
# Dropzone Destination Info
# Name: Send to iPhone
# Description: Sends dropped files, dragged text or the clipboard (on click) to your iPhone, iPad or iPod touch via myPhoneDesktop service
# Handles: NSFilenamesPboardType, NSStringPboardType
# Creator: jProductivity, LLC
# URL: http://myphonedesktop.com/
# IconURL: http://www.myphonedesktop.com/dwn/dropzone/mpd.png
# Events: Dragged, Clicked
APP_NAME = "mpd"
APP_PATH = "/Applications/myPhoneDesktop.app"
def mpd_installed?
File.exist?("#{APP_PATH}") ? true : false
end
def mpd_running?(app_name)
`ps aux` =~ /#{app_name}/ ? true : false
end
def can_send_to_mpd?
unless mpd_installed?
system("open http://www.myphonedesktop.com/")
$dz.error("myPhoneDesktop is not installed", "There is no myPhoneDesktop installed on your computer. Visit the myPhoneDesktop site to download and install myPhoneDesktop on your computer, iPhone, iPad or iPod touch.")
Process.exit
end
unless mpd_running?("myPhoneDesktop.app")
`open -a \"#{APP_PATH}\"`
sleep(5)
end
return mpd_running?("myPhoneDesktop.app")
end
def process_query(data, was_clicked)
if was_clicked
is_file_in_pb = `osascript -e '((clipboard info) as text) contains "class furl"'`
if is_file_in_pb.strip == "true"
file_path = `osascript -e 'set a to quoted form of POSIX path of ((the clipboard as «class furl») as alias)'`
data = file_path.gsub(/[\n']/i, '')
end
end
is_file = File.exist?(data) && ! File.directory?(data)
allowed_image_files = ["JPEG image", "Portable Network Graphics image", "Graphics Interchange Format (GIF)"]
allowed_text_files = ["Plain text document", "Plain Text", "Markdown document", "vCard", "comma-separated values", "Log file", "HTML document", "Cascading style sheet", "JavaScript source", "Ruby source", "SQL source"]
if is_file
file_kind = "(null)"
while file_kind == "(null)"
file_kind = `mdls -raw -name kMDItemKind "#{data}" 2>&1`
sleep(0.1)
end
if allowed_image_files.include?(file_kind) || allowed_text_files.include?(file_kind)
t = Thread.new do
`osascript -e 'set the clipboard to POSIX file "#{data}"'`
end
t.join
else
$dz.error("Unsupported File Type", "myPhoneDesktop unable to process file\n\nSupported file types include text files (txt, vCard, markdown, etc.) and images (gif, jpeg and png)")
Process.exit
end
else
if ! was_clicked
data = data.gsub(/["]/i, '\\"')
t = Thread.new do
`osascript -e 'set the clipboard to "#{data}" as Unicode text'`
end
t.join
end
end
send_to_mpd
end
def send_to_mpd
`osascript -e 'tell application "System Events"' -e 'key code 113 using {shift down, control down, option down, command down}' -e 'end tell'`
end
def dragged
# Check that we can send data to myPhoneDesktop
if not can_send_to_mpd?
$dz.finish("Unable to send to myPhoneDesktop")
$dz.url(false)
return
end
# Handle Drag
if $items.length > 1
$dz.finish("Multiple Files Unsupported")
$dz.url(false)
elsif File.directory?($items[0])
$dz.finish("Unable to Process Folders")
$dz.url(false)
else
data = $items[0]
end
process_query(data, was_clicked=false)
end
def clicked
# Check if we can send data to myPhoneDesktop
if not can_send_to_mpd?
$dz.finish("Unable to send to myPhoneDesktop")
$dz.url(false)
return
else
# Send data stored in the clipboard to myPhoneDesktop
data = `pbpaste`
process_query(data, was_clicked=true)
end
end