Skip to content

Instantly share code, notes, and snippets.

@allthesignals
Forked from eric-hu/Open iterm tab here
Last active April 7, 2016 15:24
Show Gist options
  • Select an option

  • Save allthesignals/aafd75148fed34e8c67a5b57963996ee to your computer and use it in GitHub Desktop.

Select an option

Save allthesignals/aafd75148fed34e8c67a5b57963996ee to your computer and use it in GitHub Desktop.

Revisions

  1. allthesignals revised this gist Apr 7, 2016. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions Open iterm tab here
    Original file line number Diff line number Diff line change
    @@ -15,10 +15,10 @@ on run {input, parameters}
    set dir_path to quoted form of (POSIX path of (container of my_file as string))
    end if
    end tell
    CD_to(dir_path, input)
    CD_to(dir_path, input, filetype)
    end run

    on CD_to(theDir, input)
    on CD_to(theDir, input, filetype)
    tell application "iTerm"
    set my_file to first item of input
    set my_file to quoted form of (POSIX path of my_file)
    @@ -33,7 +33,13 @@ on CD_to(theDir, input)
    tell the last session
    write text "python3"
    write text "import pandas as pd"
    write text "data = pd.read_csv(" & my_file & ")"
    write text "file_path =" & my_file
    write text "# " & filetype
    if filetype is "Microsoft Excel Workbook (.xlsx)" then
    write text "data = pd.read_excel(file_path)"
    else
    write text "data = pd.read_csv(file_path)"
    end if
    end tell
    end tell
    end tell
  2. allthesignals revised this gist Apr 7, 2016. 1 changed file with 8 additions and 5 deletions.
    13 changes: 8 additions & 5 deletions Open iterm tab here
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    --
    -- Modified to work with files as well, cd-ing to their container folder
    on run {input, parameters}
    tell application "Finder"
    tell application "Finder"
    set my_file to first item of input
    set filetype to (kind of (info for my_file))
    -- Treats OS X applications as files. To treat them as folders, integrate this SO answer:
    @@ -15,11 +15,13 @@ on run {input, parameters}
    set dir_path to quoted form of (POSIX path of (container of my_file as string))
    end if
    end tell
    CD_to(dir_path)
    CD_to(dir_path, input)
    end run

    on CD_to(theDir)
    on CD_to(theDir, input)
    tell application "iTerm"
    set my_file to first item of input
    set my_file to quoted form of (POSIX path of my_file)
    activate
    try
    set t to the last terminal
    @@ -29,8 +31,9 @@ on CD_to(theDir)
    tell t
    launch session "Default Session"
    tell the last session
    write text "cd " & theDir
    write text "ls"
    write text "python3"
    write text "import pandas as pd"
    write text "data = pd.read_csv(" & my_file & ")"
    end tell
    end tell
    end tell
  3. eric-hu revised this gist Jun 23, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Open iterm tab here
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,8 @@ on run {input, parameters}
    tell application "Finder"
    set my_file to first item of input
    set filetype to (kind of (info for my_file))
    -- Treats OS X applications as files. To treat them as folders, integrate this SO answer:
    -- http://stackoverflow.com/a/6881524/640517
    if filetype is "Folder" or filetype is "Volume" then
    set dir_path to quoted form of (POSIX path of my_file)
    else
  4. eric-hu created this gist Jun 23, 2013.
    35 changes: 35 additions & 0 deletions Open iterm tab here
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    -- Adapted from these sources:
    -- http://peterdowns.com/posts/open-iterm-finder-service.html
    -- https://gist.github.com/cowboy/905546
    --
    -- Modified to work with files as well, cd-ing to their container folder
    on run {input, parameters}
    tell application "Finder"
    set my_file to first item of input
    set filetype to (kind of (info for my_file))
    if filetype is "Folder" or filetype is "Volume" then
    set dir_path to quoted form of (POSIX path of my_file)
    else
    set dir_path to quoted form of (POSIX path of (container of my_file as string))
    end if
    end tell
    CD_to(dir_path)
    end run

    on CD_to(theDir)
    tell application "iTerm"
    activate
    try
    set t to the last terminal
    on error
    set t to (make new terminal)
    end try
    tell t
    launch session "Default Session"
    tell the last session
    write text "cd " & theDir
    write text "ls"
    end tell
    end tell
    end tell
    end CD_to