Skip to content

Instantly share code, notes, and snippets.

@ivankahl
Created April 28, 2015 21:41
Show Gist options
  • Save ivankahl/1e98f3890065b79e8a6b to your computer and use it in GitHub Desktop.
Save ivankahl/1e98f3890065b79e8a6b to your computer and use it in GitHub Desktop.
Open In.py
import console
import editor
import os
def main():
# Get the path to the file or select the current file open in the editor
path = console.input_alert('File Path', 'Enter the path to the file you want to open relative to the Documents directory Leave <CURRENT> to open current file', '<CURRENT>', 'Open In')
# Check if text was returned
if not path:
# Cancel the app if no text was provided (was probably cancelled)
return
# Check if the text returned was <CURRENT>
if path == '<CURRENT>':
# Get the path to the current file open
path = editor.get_path()
# If path was <CURRENT> but no file was open, stop
if path == None:
console.alert('Error', 'No file path was provided or found in the editor')
return
# Check if the path exists
if os.path.exists(path):
# If so, open the file
console.open_in(path)
else:
# Alert the user if no file was found
console.alert('Error', 'The file was not found.')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment