The problem is on this line:
clipboard = os.system("pbpaste")
Here's why:
In [3]: ?os.system
Type: builtin_function_or_method
String Form:<built-in function system>
Docstring:
system(command) -> exit_status
Execute the command (a string) in a subshell.
os.system returns the exit status of the command, not the stdout of the command.
Try the subprocess module instead:
import subprocess
clipboard = subprocess.check_output('pbpaste', shell=True)
Bear in mind, though, that it may be blank (or have less than five characters), which will cause your program to crash when you do clipboard[:4]
. Best practice is to check the length of a sliceable object before slicing it: if (len(clipboard) > 4)
, or better yet, if (clipboard.startswith('http'))
.
Good luck and happy coding!