vladimirnani / DjangoCommands

ST2/ST3 plugin for managing django project
29 stars 14 forks source link

AppleScript for iTerm2 #29

Closed yaroslavyaroslav closed 1 year ago

yaroslavyaroslav commented 7 years ago

Thanks for a great plugin. It's very useful!

in my case i'm using iTerm2 as a main terminal in OSX, and your plugin is hardcoded to use default Terminal.app in it. So it's a bit uncool to use separate term app just to run Django commands. And i've modified your plugin, the part which is run command in the OSX case, to use iTerm only.

In my case i've just hardcode it to iterm either. And here's the list that calls iterm instead Terminal.

if PLATFORM == 'Darwin':
    command = [
        'osascript',
        '-e', 'tell application "iTerm"',
        '-e', 'tell current window to create tab with profile "Default" command "{0}"'.format(command),
        '-e', 'end tell'
    ]

I'd test it for myself and it seems working. Hope you'll add this as option in to your main branch in one of the following updates.

mxdevmanuel commented 7 years ago

It sounds like a great request, I would love to enhance OsX users experience with the plugin unfortunately I don't have an apple computer so, maybe you can give me some insight about this, for example which options of the script would be cool to change based on the user defined settings, along with the option to define your favorite term in your settings. Thank you very much for your feedback and I will work on this ASAP.

El mar. 5, 2017 13:46, "yaroslavyaroslav" notifications@github.com escribió:

Thanks for a great plugin. It's very useful!

in my case i'm using iTerm2 as a main terminal in OSX, and your plugin is hardcoded to use default Terminal.app in it. So it's a bit uncool to use separate term app just to run Django commands. And i've modified your plugin, the part which is run command in the OSX case, to use iTerm only.

In my case i've just hardcode it to iterm either. And here's the list that calls iterm instead Terminal.

      command = [
            'osascript',
            '-e', 'tell application "iTerm"',
            '-e', 'tell current window to create tab with profile

"Environment: Dossier" command "{0}"'.format(command), '-e', 'end tell' ]

I'd test it for myself and it seems working. Hope you'll add this as option in to your main branch in one of the following updates.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vladimirnani/DjangoCommands/issues/29, or mute the thread https://github.com/notifications/unsubscribe-auth/ADxhZM-npqp_J_w5ZfaiHtBCOj8MYbxFks5rixEegaJpZM4MThWf .

yaroslavyaroslav commented 7 years ago

AFAIK there is no main setting to choose different terminal app against system one both systemwide and sublime text usage. So in every single case you've just to write it manually in configurations of your app. In case of sublime there is just an option in every single plugin (which is support this feature of course) settings which is choosing which terminal app do you prefer. The example of this setting can be seen in this plugin[1]. IMO this is not the best realisation of the terminal chose (i mean bash scripting), but in any case it works properly.

So as for me, in case of your plugin, there'll be enough just to make addition option to switch which terminal mac user want use. And maybe the simplest way is just to make another if condition which is depends from that option. If user wants to use default one — use your version applescript, if iTerm — mine.

[1] https://github.com/wbond/sublime_terminal https://github.com/wbond/sublime_terminal

6 марта 2017 г., в 0:09, Manuel Morales notifications@github.com написал(а):

It sounds like a great request, I would love to enhance OsX users experience with the plugin unfortunately I don't have an apple computer so, maybe you can give me some insight about this, for example which options of the script would be cool to change based on the user defined settings, along with the option to define your favorite term in your settings. Thank you very much for your feedback and I will work on this ASAP.

El mar. 5, 2017 13:46, "yaroslavyaroslav" notifications@github.com escribió:

Thanks for a great plugin. It's very useful!

in my case i'm using iTerm2 as a main terminal in OSX, and your plugin is hardcoded to use default Terminal.app in it. So it's a bit uncool to use separate term app just to run Django commands. And i've modified your plugin, the part which is run command in the OSX case, to use iTerm only.

In my case i've just hardcode it to iterm either. And here's the list that calls iterm instead Terminal.

command = [ 'osascript', '-e', 'tell application "iTerm"', '-e', 'tell current window to create tab with profile "Environment: Dossier" command "{0}"'.format(command), '-e', 'end tell' ]

I'd test it for myself and it seems working. Hope you'll add this as option in to your main branch in one of the following updates.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vladimirnani/DjangoCommands/issues/29, or mute the thread https://github.com/notifications/unsubscribe-auth/ADxhZM-npqp_J_w5ZfaiHtBCOj8MYbxFks5rixEegaJpZM4MThWf . — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vladimirnani/DjangoCommands/issues/29#issuecomment-284262853, or mute the thread https://github.com/notifications/unsubscribe-auth/AP17l-efDf8M97lcUIDCzcv0jNsLpVdIks5riyR6gaJpZM4MThWf.

mxdevmanuel commented 7 years ago

All I'm not well versed with OSX but I can add a setting to define the the terminal each person wants, aside from the default and iTerm and append the -e sentences that fits each persons workflow like this:

"osx_terminal": {
    "terminal": "iTerm",
    "instruction": "tell current window to create tab with profile "Environment: Dossier" command '{0}'"
      "options": [
           "end tell"
        ]}

where terminal is the terminal to execute, intstrucion is the string to be formated with the selected command and options are string to append with its corresponding '-e' option.

or

"osx_terminal": {
    "separator": "$",
    "instruction": 'tell application "iTerm"$tell current window to create tab with profile
    "Environment: Dossier" command "{0}"$end tell'

where separator is the character to split the string and each 'substring' are: -1 The term to use -2 The string to be formatted with the command to run -3+ any option to be append

which of these approaches do you think could be more confortable for OSx users?

Thanks for your time

yaroslavyaroslav commented 7 years ago

It seems that the formatting of the code in your last message were quite broken, so I'm afraid that I'm not quite clear understand both of your examples, specially second one. Also I've been a bit modify my main message about it's code part, so I think you should see it in the browser to get more actual info.

But in any case let me describe what is going on in that code that I'd put in my first comment and I'll be using here my last version of it:

if PLATFORM == 'Darwin':
    command = [
        'osascript',
        '-e', 'tell application "iTerm"',
        '-e', 'tell current window to create tab with profile "Default" command "{0}"'.format(command),
        '-e', 'end tell'
    ]

The all things happening from the fourth line: 4 line: is command to OSX framework that all following text will be addressed to exact application, also it's service command which is equal to open bracket in other language, which must be closed in the script. 5 line: the command to that application, which is about to create a new tab with Default profile and to run a command in it, that will be fitted by format() from your plugin 6 line: the service command which is equal to close bracket in other languages.

And one more important thing about that option:

My script works only for iTerm. I've just checked it manually — it's not working if you change iTerm to Terminal in it. This happens because AppleScript is quite awful tool if we talking about standards. So to be clear my solution, i mean code, is working only in case of using iTerm to run commands from your plugin, and your solution, which is in production now, are working only with the default Terminal.app to run commands from your plugin. And maybe there is a way to made AppleScript code which will be fit above cases above, but unfortunately i'm quite noob in that language and don't know it.

But the good news is that there is only two popular terminal application in OSX. And there both mentioned in this topic, so as for me, I'd suggest you to give user an option to choose one of thees two solutions directly. And based on their choice there just one of two AppleScripts above are running.

6 марта 2017 г., в 5:28, Manuel Morales notifications@github.com написал(а):

All I'm not well versed with OSX but I can add a setting to define the the terminal each person wants, aside from the default and iTerm and append the -e sentences that fits each persons workflow like this:

"osx_terminal": { "terminal": "iTerm", "instruction": "tell current window to create tab with profile "Environment: Dossier" command '{0}'" "options": [ "end tell" ]}

where terminal is the terminal to execute, intstrucion is the string to be formated with the selected command and options are string to append with its corresponding '-e' option.

or

"osx_terminal": { "separator": "$", "instruction": 'tell application "iTerm"$tell current window to create tab with profile "Environment: Dossier" command "{0}"$end tell'

where separator is the character to split the string and each 'substring' are: -1 The term to use -2 The string to be formatted with the command to run -3+ any option to be append

which of these approaches do you think could be more confortable for OSx users?

Thanks for your time

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vladimirnani/DjangoCommands/issues/29#issuecomment-284287900, or mute the thread https://github.com/notifications/unsubscribe-auth/AP17l4D07rBETTJfC6_D5gqma5pYyjjhks5ri29bgaJpZM4MThWf.

mxdevmanuel commented 7 years ago

There's now a setting to set the terminal in which commands will be run, I have'nt fully tested it yet, cauze I cannot access my universities iMac lab, I lost my access card :1st_place_medal: , so I don't have a Mac close by, a friend of mine made some tests, but nothing to deep. I hope you would be kind enough to give it a try.