Skip to content

Instantly share code, notes, and snippets.

@RhetTbull
Created August 4, 2019 19:19
Show Gist options
  • Save RhetTbull/4d3a91fceeb040a68ef0dd0fc049dce5 to your computer and use it in GitHub Desktop.
Save RhetTbull/4d3a91fceeb040a68ef0dd0fc049dce5 to your computer and use it in GitHub Desktop.
Print full path of a file and copy the path to the OS X clipboard
#!/usr/bin/env python3
import os.path
import os
import sys
import subprocess
def write_to_clipboard(output):
process = subprocess.Popen(
'pbcopy', env={'LANG': 'en_US.UTF-8'}, stdin=subprocess.PIPE)
process.communicate(output.encode('utf-8'))
if __name__ == "__main__":
if len(sys.argv) == 2:
fname = sys.argv[1]
cwd = os.getcwd()
path = os.path.realpath(os.path.join(cwd, fname))
write_to_clipboard(path)
print(path)
else:
print(f"Usage:\n{sys.argv[0]} file_name\nPrints full path and copies to OS X clipboard")
quit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment