Chomper Stomping
jQuery/JavaScript/CSS 3/HTML 5, Java/PHP/Python/ActionScript, Git, Chrome/Firefox Extensions, Wordpress/Game/iPhone App Development and other random techie tidbits I've collected



Tools

October 4, 2008

Auto Upload File on Save in Aptana

More articles by »
Written by: Christopher McCulloh
Tags: , , , ,

This is an explanation on how to automatically upload a file via FTP when you click “save” in the Aptana IDE (2.x does not work in 3.x). Let’s jump right in…

1. If you don’t have a project, create one. 

2. If you don’t have a “scripts” folder in your project, create one (I put mine in the root directory of my project. No clue if it will work from anywhere else). 

3. Create a new file inside your scripts folder with a .js extension (I named mine “upload_current_file_on_save.js”, not sure if it will work with any other name). 

4. Place this code inside the file: 

 

Code:
/* 
 * Menu: gMan > Upload On Save 
 * Kudos: Ingo Muschenetz 
 * License: EPL 1.0 
 * Listener: commandService().addExecutionListener(this); 
 * DOM: http://localhost/com.aptana.ide.syncing 
 * DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript 
 */  

// Add  * Listener: commandService().addExecutionListener(this); to the top of this file to enable it 

/** 
 * Returns a reference to the workspace command service 
 */ 
function commandService() 

   var commandServiceClass = Packages.org.eclipse.ui.commands.ICommandService; 
    
   // same as doing ICommandService.class 
    var commandService = Packages.org.eclipse.ui.PlatformUI.getWorkbench().getAdapter(commandServiceClass); 
    return commandService; 

/** 
 * Called before any/every command is executed, so we must filter on command ID 
 */ 
function preExecute(commandId, event) {} 

/* Add in all methods required by the interface, even if they are unused */ 
function postExecuteSuccess(commandId, returnValue) 
 { 
    
   // if we see a save command 
   if (commandId == “org.eclipse.ui.file.save”) 
   { 
      sync.uploadCurrentEditor(); 
       
      /* Replace above line if you’d like to limit it to just certain projects 
      var fileName = editors.activeEditor.uri; 
      if(fileName.match(/projectName/ig)) 
      { 
         sync.uploadCurrentEditor();    
      } 
      */ 
    } 

function notHandled(commandId, exception) {} 

function postExecuteFailure(commandId, exception) {}

 

5. Save the file. 

A few notes on what needed changed in this file from the sample file I took this from: 

1. I added this line of code to the comment block at the top: 

 

Code:
 * Listener: commandService().addExecutionListener(this);

 

I know there is a comment in this file that tells you to “add this to the top of this file”, but since I’m new to the whole scripts thing I didn’t get that when it said “top of the file” it meant “the middle of the comment block at the top of this file”. I thought I was literally supposed to make that line the very first line in the file… Which didn’t work at all… 

2. I changed the “menu” line to: 

 

Code:
 * Menu: gMan > Upload On Save 


from: 

 

Code:
 * Menu: Synchronize > Upload Current File On Save Enabled

 

For some reason it didn’t work until I changed this line. Since my project is code named “gMan” (It’s a user management system, you’ll make the connection…) I just named the menu item “gMan” after my project. Then the command is to upload on save, so that’s what I named it. As soon as I made this change is when the whole thing started working. Could be coincidence, or could be that you have to do this for the script to work (rename the menu command something other than what the sample is named). 

In case you haven’t figured it out, you run the script by going to the “Scripts” menu in the toolbar at the top of Apatan (and selecting the script, whatever you named it in the previous step). 

Want to read more about website creation in Aptana from this author? Check out his book:
HTML, XHTML, and CSS All-in-One Desk Reference For Dummies (For Dummies (Computer/Tech)). Support the Author of this post and buy the book from Amazon by clicking on the link on this page. Thanks for the help!




About the Author

Christopher McCulloh
E-Commerce developer at Finish Line Co-Author of HTML, XHTML and CSS All-in-one Desk Reference for Dummies Graduated from IU with a Bachelors of Media Arts and Science and a Certificate in Applied Computer Science. Tech Editor for Building Facebook Applications for Dummies and Building Websites All-in-one for Dummies 2nd Edition. Creator and maintainer of the Status-bar Calculator Firefox Extension Three years professional experience in Java E-Commerce Development and four years professional experience with PHP for a combined total of seven years professional JavaScript/HTML/CSS experience




 
 

 
cloudwars

Let the Cloud Wars Begin!!!

This is all going the same direction. They are all going to end up with unlimited storage for the same price point per year, so, the sooner one of them calls it and just offers that, the better that one will do. They need to ju...
by Christopher McCulloh
0

 
 
 

Events Calendar Pro Nav Formatting Messed up on Empty Calendar

The Events Calendar Pro (from http://tri.be/) has a few problems. If you are trying to figure out why a calendar with no events in that month has completely screwed up header navigation, just put this line of code inside of tab...
by Christopher McCulloh
5

 
 
octocat

Introducing GitScripts

GitScripts is a project that attempts to make Git user friendly. I have been working on it for almost a year now. When we implemented Git in my office, we were having a really hard time using it. We loved the flexibility of the...
by Christopher McCulloh
1

 

 
tabedit

Updates – Tab Edit 1.4, Abandoning JS Console, Limeberry news

It’s apparently Code Blitz week here at Chomperstomp.com HQ. We’ve seen 5 blog posts in the last week, and code commits to no less than 4 open source projects (plus tons behind the scenes that I won’t talk abo...
by Christopher McCulloh
0

 
 
HTML5_Styling_512

Introducing Limeberry

Limeberry is a CSS 3 Finely Granular Color Gradient Generator. It allows you to input very precise (up to the nth decimal) numeric values to be used as your gradient color stops. Choose how many color stops you want and then de...
by Christopher McCulloh
0

 




17 Comments


  1. genius, thanks!!

    It seemed to work straight away, there was no need to go to the scripts menu and enable it. But after I read this post (I originally found the script in the forum too) I went ahead and went to Script > gMan > Upload on Save and got this error:

    function main() is not defined in (/Users/mymachinename/Sites/workspace/myprojectname/scripts/upload_current_file_on_save.js


  2. That’s odd… Are you still getting the error (did you try restarting Aptana)?


  3. Yeah I’m having the same problem as jyoseph. I’ve tried restarting too.


  4. Vinny

    i get the same error


  5. Lyall

    Me too, main() is not defined blah blah… :(


  6. Rocky Madden

    For those having issues, ensure you move the script out of the default location into a local folder called “scripts” in the root of your project. Even when a constructor is made in the default location, it doesn’t seem to work. Hope that helps.


  7. None of the above worked for me … after much searching, found the answer at: http://snipplr.com/view.php?codeview&id=19884

    Look like 2 things:

    1) Should be DOM: http://localhost/com.aptana.ide.syncing.doms

    2) Needs function main() {} above command Service

    have fun :)


  8. Felix

    Does not work for PHP-Files?!
    ..but its working on .html and .css quite perfect.


  9. Felix

    Got it to work.
    I used Eclipse and Aptana as a plugin.
    You need to install APTANAS PDT-PLUGIN as well, to make the auto-smart-sync recognize *.php.


  10. Jason

    I am running ecplipse PDT with Aptana as a plugin. I am able to upload on save *.html, *.js, *.css, etc. However, *.php files do not upload on save. What is ‘APTANAS PDT-PLUGIN’ and where do I find it? It sounds like it is just the eclipse PDT running in Aptana Studio. How do I get scripts/upload_current_file_on_save.js to push *.php files?


  11. Note that JavaScript scripting is only available on Aptana2.x.
    On Aptana 3.0 the scripting is only available via Ruble (ruby).
    see: https://aptanastudio.tenderapp.com/faqs/scripting-aptana-studio/ruble-programming-guide


  12. This works perfectly with Aptana 2.0:
    http://juergen-schwind.de/Save-and-Upload-Current-File-fuer-Aptana-Studio-1-5_9.html

    It is much cleaner, and is functioning with all file types(including php). I installed it in scripts directory of current project. Somewhere I read that you could make project e.g. “Nice Scripts” where you could save all your scripts that you want to work in all projects. And than reference that project in other projects, did not tried it but maybe someone will need it.

    Ivan.


  13. Neither of these solutions work with PHP files for me. The first solution works great for every other file-type EXCEPT PHP, and the second one doesn’t seem to do anything for me. I am using Eclipse Helios 3.6.1 with Aptana Studio 2 – Why on earth the most common server-side scripting file-type in the universe is not supported by Aptana Studio makes about as much sense as tits on a great white shark.

    For those of you PHP devs out there who have searched the internet far and wide with no luck finding a solution to this annoying issue, I have what I consider to be the next best thing.

    Install these keys: http://www.jaynay.com/util/MyEclipseKeys.csv

    This keymap set is the default keymap that comes with Eclipse Helios 3.6.1 with the addition of an upload shortcut.

    This works with the File view window as you main file-list viewer. First, make sure you have enabled “Link with Editor” (the icon at the top of the File view window that has two gold horizontal arrows). Now when your editing a file of any file-type (context: Editing in Structured Text Editors) and you want to save & upload the current file, you can use the following key strokes:

    CTRL+S (saves the file)

    CTRL+SHIFT+U (will switch to the File view window, since you have “Link with Editor” enabled, your current file will already be highlighted)

    CTRL+SHIFT+U (will upload the file)

    It may seem like a pain in the ass to read these instructions but the actual process is super simple and you can do it with you eyes closed and without even thinking after about 5 minutes.

    I chose CTRL+SHIFT+U because that was the key command I usedto use in Dreamweaver to “Put” a file onto a remote server. Obviously you can set whatever keys you like.

    Anyways, take it for what it’s worth. It’s a shitload better than using a mouse to navigate through context menus every time you want to upload your PHP files.

    Word.
    Jay


  14. Yes, Ctrl + Shift + U will upload the current file. Unfortunately, it doesn’t prompt for save or anything, so you have to hit Ctrl + s and then Ctrl + Shift + U to save and upload.

    I’m looking around for some other solutions, and may end up just writing an Eclipse plug-in myself…


  15. I’m running Aptana 1.5 still and this worked for me after I made the changes Gabriel Nagmay noted above. Uploads my .php files when I save them.


  16. Instead of creating a folder called script in your project root, it’s better to create a new project just for that, and add that project as an reference. This way you can have that script or others without influence your current project. I have the same thing using the snipets.

    :D


  17. Troy

    For Titanium studio 3 users, there is a connection wizard that provides an option for this, no scripting needed.
    http://wiki.appcelerator.org/display/tis/FTP,+SFTP,+and+FTPS+Deployment



Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>