@@ -11,7 +11,7 @@ def publish_drafts_to_posts():
11
11
today = datetime .date .today ()
12
12
date_str = today .strftime ('%Y-%m-%d' )
13
13
14
- drafts_dir = " _drafts"
14
+ drafts_dir = ' _drafts'
15
15
posts_en_dir = os .path .join ('_posts' , 'en' )
16
16
17
17
if not os .path .exists (drafts_dir ):
@@ -40,25 +40,30 @@ def publish_drafts_to_posts():
40
40
except Exception as e :
41
41
print (f"Error moving '{ file_name } ': { e } " )
42
42
43
- # Restart VSCode to close open tabs and prevent accidental editing of moved files
44
43
restart_vscode ()
45
44
46
45
def restart_vscode ():
47
- print ("Restarting VSCode to prevent accidental re-creation of draft files..." )
48
- if sys .platform == 'win32' :
49
- os .system ('taskkill /f /im Code.exe /t' )
50
- time .sleep (2 )
51
- subprocess .Popen (['code' , '.' ])
52
- elif sys .platform == 'darwin' :
53
- os .system ("pkill -f 'Visual Studio Code'" )
54
- time .sleep (2 )
55
- subprocess .call (['open' , '-a' , 'Visual Studio Code' , '.' ])
56
- elif sys .platform .startswith ('linux' ):
57
- os .system ('killall code' )
58
- time .sleep (2 )
59
- subprocess .Popen (['code' , '.' ])
60
- else :
61
- print ("Unsupported platform for restarting VSCode." )
46
+ print ("Restarting VSCode gracefully to prevent accidental re-creation of draft files..." )
47
+ try :
48
+ if sys .platform == 'win32' :
49
+ # Graceful close without /f
50
+ os .system ('taskkill /im Code.exe /t' )
51
+ time .sleep (3 ) # Delay for cleanup
52
+ subprocess .Popen (['code' , '.' ]) # Reopen
53
+ elif sys .platform == 'darwin' :
54
+ # Use AppleScript for graceful quit
55
+ os .system ('osascript -e \' quit app "Visual Studio Code"\' ' )
56
+ time .sleep (3 )
57
+ subprocess .call (['open' , '-a' , 'Visual Studio Code' , '.' ])
58
+ elif sys .platform .startswith ('linux' ):
59
+ # SIGTERM for graceful termination
60
+ os .system ('killall code' )
61
+ time .sleep (3 )
62
+ subprocess .Popen (['code' , '.' ])
63
+ else :
64
+ print ("Unsupported platform for restarting VSCode." )
65
+ except Exception as e :
66
+ print (f"Error during restart: { e } . Please manually restart VSCode." )
62
67
63
68
if __name__ == "__main__" :
64
69
publish_drafts_to_posts ()
0 commit comments